这是为了完成家庭作业而我很困惑该做什么。它要求我创建一个项目作为用户定义的函数,然后使其绘制,以便绘图根据我的鼠标的X和Y坐标移动。它还要求我在接近画布的顶部和底部时改变它的大小。 目前,我已经完成了我的绘图并尝试使用另一个用户定义的函数来移动它,但我没有多少运气。
int xCtr = width/2, yCtr = height/2; //Center
final int SAUCEHEIGHT = 150, SAUCEWIDTH = 200;
int foodSize;
int positionX = mouseX, positionY = mouseY;
void setup(){
//Parameters and variables
size(500,500); //Canvas size
background(0,0,225); //blue background
}
void drawFood(){
//Plate
/*
*This function is used to sketch a beige ellipse.
*The inputs for this function come from the filling and the ellipse which uses the int xCtr and yCtr.
*The output of the function creates a beige plate.
*For fill, data stored as int are used in its parameters, where as for ellipse, the data is stored as floats.
*/
fill(245,245,220); //beige
ellipse(xCtr,yCtr,width,height); //plate
//Rice
/*
*This function is used to sketch a white ellipse.
*The inputs for the function come from fill and ellipse, with the ellipse using int xCtr and yCtr.
*The output of the function is white rice.
*Fill stores the data in int, and ellipse stores its data in float.
*/
fill(255,255,255); //white
ellipse(xCtr,yCtr,width*2/3,height*2/3); //White Rice
//Sauce
/*
*This function is used to sketch a brown ellipse
*The inputs are fill and ellipse. Ellipse uses the int xCtr and yCtr.
*The output of the function is a brown sauce.
*Fill stores the data in int, and ellipse stores its data in float.
*/
strokeWeight(2); //Better defined border
fill(134,100,79); //Gravy Brown
ellipse(xCtr-50,yCtr-100,SAUCEWIDTH,SAUCEHEIGHT); //Sauce
//Steak
/*
*This function is used to sketch a thick brown line.
*The inputs for the function come from strokeWeight, stroke, and line.
*The output of the function is a steak with grill marks.
*StrokeWeight uses float, stroke uses int, and line uses floats.
*/
strokeWeight(150); //thickness
stroke(125,64,7); // Gordon Ramsay Steak Brown
line(xCtr+50,yCtr+50,xCtr+150,yCtr+50); //Steak
//Grill Marks
/*
*This function is used to sketch a checkered pattern.
*The inputs for the function come from strokeWeight, stroke, and line.
*The output of the function are grill marks.
*StrokeWeight uses float, stroke uses int, and line uses floats.
*/
strokeWeight(2);
stroke(0,0,0); //black
//Vertical Grill Lines
line(xCtr+50,yCtr-20,xCtr+50,yCtr+120); //1st Vertical
line(xCtr+100,yCtr-20,xCtr+100,yCtr+120); //2nd Vertical
line(xCtr+150,yCtr-20,xCtr+150,yCtr+120); //3rd Vertical
//Horizontal Grill Lines
line(xCtr-20,yCtr+25,xCtr+220,yCtr+25);
line(xCtr-20,yCtr+75,xCtr+220,yCtr+75);
}
void moveFood(){
foodSize = mouseY/height;
}
我可以做些什么来改变它,还是有任何可能有用的参考?
感谢您抽出宝贵时间回答。
答案 0 :(得分:0)
Stack Overflow实际上并不是针对一般的“我该怎么做”这类问题而设计的。这是针对具体的“我试过X,期待Y,但得到Z而不是”类型的问题。但我会尝试在一般意义上提供帮助:
现在,您的drawFood()
函数使用xCtr
和yCtr
变量来了解绘制所有内容的位置。你的作业要求你将参数传递给drawFood()
函数并改用它们。
您需要break your problem down into smaller steps并一次一个地执行这些步骤。你能创建一个只绘制简单形状的小例子程序,如圆圈吗?将它放在一个函数中,该函数使用草图级变量来决定绘制圆的位置。然后修改该函数,使其使用参数。在尝试让它完成整个家庭作业之前,先在您的小型示例程序中使用它。然后,如果您遇到问题,可以发布MCVE以及特定的技术问题。祝你好运。
无耻的自我推销:我写了一篇关于创建带有参数here的函数的教程。