代码之家  ›  专栏  ›  技术社区  ›  Lefter Emil

如何将变量重置回其完整值?

  •  1
  • Lefter Emil  · 技术社区  · 7 年前

    如何将y重置回完整值?模算子作用于x,因为变量从0开始,一直增加到宽度,但我不知道写什么来将y重置为全值。我不能使用超过2个声明的变量。谢谢你的帮助。

    int y=height;
    int x=0;
    
    void setup()
    {
        size(100,100);
        frameRate(30);
    }
    
    void draw()
    {
        background(200);
        line(0,y,width,y); //bottom to top
        line(0,x,width,x); // top to bottom
        line(y,0,y,height); //left to right
        line(x,0,x,height); //right to left
        y=y-1;
        x = (x+1) % width;
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Kevin Workman    7 年前

    if 当变量达到某个值时重置该变量的语句。类似这样:

    y = y - 1;
    if(y < 0){
      y = height;
    }
    

    无耻的自我推销:我写了一篇关于处理中的动画的教程,包括这种重置技术 here .