PROCESSING | Sketch 1

PROCESSING | Sketch 1





float [] x;
float [] y;
float [] xDelta;
float [] yDelta;
int numOfBalls = 8;

void setup() {
  size(500,500);
  frameRate (60);
  
  x = new float[numOfBalls];
  y = new float[numOfBalls];
  xDelta = new float[numOfBalls];
  yDelta = new float[numOfBalls];
    
  for(int i=0; i<numOfBalls; i++) {
   x[i] = random(10,490);
   y[i] = random(10,490);
   xDelta[i] = random(-10,10);
   yDelta[i] = random(-10,10);
  }
  
  for(int i=0; i<numOfBalls; i++) {
   ellipse(x[i], y[i], 20, 20); 
  }
}

void draw() {
 background(2);

  for(int i=0; i< numOfBalls; i++) {
   ellipse (x[i], y[i], 20, 20);
   fill (random(0,255), random(0,255), random(0,255));
   stroke (random(0,255), random(0,255), random(0,255));
   strokeWeight (y[i]);
    x[i] = x[i] + xDelta[i];
    y[i] = y[i] + yDelta[i];
    
     if((x[i] > width-10) || (x[i] < 10)) {
     xDelta[i] = -xDelta[i];
  }
   
     if((y[i] > height-10) || (y[i] < 10)) {
     yDelta[i] = -yDelta[i];
   }
 }

0 comentarios:

Publicar un comentario