2013年10月20日 星期日

week 07


int area=30;
float posx, posy;


float xspeed = 3;
float yspeed = 2.2;

int xdirection = 1;
int ydirection = 1;


void setup()
{
  size(1080, 650);
  noStroke();
  frameRate(100);
  ellipseMode(CENTER);
  posx = width/2;
  posy = height/2;
}

void draw()
{
  background(0);
  posx = posx + ( xspeed * xdirection );
  posy = posy + ( yspeed * ydirection );
  if (posx > width-area || posx < area) {
    xdirection *= -1;
  }
  if (posy > height-area || posy < area) {
    ydirection *= -1;
  }

  ellipse(posx, posy, 30, 30);
}

沒有留言:

張貼留言