在加工中制作新形状时,消失旧形状

时间:2017-08-09 09:33:41

标签: processing shapes

我希望在制作新形状时使旧形状消失。请帮我。基本上,我想在点击时创建一个矩形但是当我再次点击时,圆圈应该消失。这应该以相同的概率发生。

void setup()
{
    size(400, 400);
    background(255);
}

void draw()
{
    fill(255);
    tileAp();    
}

void tileAp()
{    
    if (mousePressed && mouseY >= 0 && mouseY <= 200)
    {    
        drawM(true);
    }
    else
    {    
    }
}

void drawM(boolean b)
{
    int prob = int(random(0, 2));
    if (b == true)
    {
        if (prob == 0)
        {
            rect(mouseX, mouseY, 50, 50);
        }

        if (prob == 1)
        {
            ellipse(mouseX, mouseY, 50, 50);
        }    
    }
}

1 个答案:

答案 0 :(得分:0)

suggested duplicate说的一样,您需要调用background()函数来清除旧框架。

比较这个草图:

&#13;
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.6.6/processing.min.js"></script>
<script type="application/processing">

void setup(){
  size(200, 200);
  background(64);
}

void draw(){
 ellipse(mouseX, mouseY, 20, 20);
}

</script>
<canvas> </canvas>
&#13;
&#13;
&#13;

对此:

&#13;
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.6.6/processing.min.js"></script>
<script type="application/processing">

void setup(){
  size(200, 200);
}

void draw(){
 background(64);
 ellipse(mouseX, mouseY, 20, 20);
}

</script>
<canvas> </canvas>
&#13;
&#13;
&#13;