ICC
< back to sketch

// bounce

float x;
float y;
int x_direction;
int y_direction;
float x_speed;
float y_speed;;
float mouse_speed;

void setup(){
   size(300, 300);
   x_direction = 1;
   y_direction = 1;
   x_speed = 3.5;
   y_speed = 2.8;
}

void loop(){
   mouse_speed = mouseX/100;
   x = x + x_direction*x_speed*mouse_speed;
   y = y + y_direction*y_speed;
   
   background(255,255,255);
   fill(0,0,255);
   ellipse(x,y,50,50);
   
   if(x > 300-50 || x < 0){
     x_direction = x_direction*-1;
   }
   
   if(y > 300-50 || y < 0){
     y_direction = y_direction*-1;
   }
}

< back to sketch