我的作业要求我编写一个类似于盘子的椭圆,并使用if else语句和shiffmans处理初学者书中的第1-6章中包含的所有内容堆叠其中的20个。我需要使用一个按钮按下功能来堆叠20个盘子,一旦它们到达20个“盘子”必须单独消失到一个一个带有鼠标点击功能。这是我到目前为止所提出的,这些印版必须从屏幕底部开始。
// Declare global (shared) variables here
float plate1X = 50;
float plate1Y = 200;
int plateColor = (255);
// Do not write any statements here (must be inside methods)
void setup()`enter code here`
{
// Add statements to run once when program starts here. For example:
size(400,400);
plate1X = 200;
plate1Y = 50;
background(255);
plate1X = width/2;
plate1Y = height/2;
} // end of setup method
void draw()
{
// Declare local variables here (new each time through)
// Add statements to run each time screen is updated here
ellipse(plate1X, plate1Y, 200,50);
if(ellipse <= 1 || ellipse <= 0; //draw another plate);
// Screen will be repainted automatically at the end of draw method
} // end of draw method
// Add other methods here
答案 0 :(得分:0)
&#34;没有检测到变量&#39; ellipse&#39;&#34;:那是因为你没有声明它。在使用之前,您需要让编译器知道它是什么类型的变量。在这种情况下,它可能是一个整数,所以你第一次使用它时应该有int ellipse;
行。
您也永远不会将ellipse
设置为保留任何值!您正在尝试检查if(ellipse <= 1 || ellipse <= 0)
,但现在ellipse
没有任何价值。
您的椭圆函数似乎应该在您告诉它的坐标处绘制一个椭圆 -
ellipse(x, y, width, height)
因此,如果您想绘制另一个椭圆,则应使用新的ellipse(...)
和x
值再次致电y
。
你会想要使用if语句来确保你只在某些时候这样做 - 特别是当你还没有获得20个牌照时。你知道if和else语句会怎么做?