Exemplos da aula de 6/5

6 maio, 2009 (18:17) | Sem categoria | Por: admin

EXEMPLO 1:

int x,y;
void setup() {
  size(300, 200);
}
void draw() {
  background(255);
  rect(width/3, height/3, width/3, height/3);
  x = constrain(mouseX, width/3, width/3*2);
  y = constrain(mouseY, height/3, height/3*2);
  ellipse(x, y, 10, 10);  
}

EXEMPLO 2:

float x, y;
void setup() {
  size(300,200);
  x = width/2;
  y = height/2;
  frameRate(5);
}
void draw() {
  background(255);
  x = x + random(-10, 10);
  y = y + random(-10, 10);
  // Nesse momento você pode restringir o valor de x e y com
  // a função constrain
  ellipse(x,y,10,10);
}