ICC
< back to sketch

float x,y,i,j;

int x_direction,y_direction,i_direction, j_direction;

float x_speed,y_speed,i_speed, j_speed;

void setup(){

  size(300,300);
  x=width/2;
  y=height/2;
  i=width/3;
  j=height/3;
  x_direction=1;
  y_direction=1;
  i_direction=1;
  j_direction=1;
  x_speed=1.2;
  y_speed=1.8;
  i_speed=3.1;
  j_speed=1.0;

}

void loop(){
  background(255-x,0,0);

  DrawObject1();
  DrawObject2();
  line(x+15,y+15,j+25,i+25);
  line(x,y,j,i);
  line(x+30,y+30,j+50,i+50);

}

//object1
void DrawObject1(){

  x=x+x_direction*x_speed;
  y=y+y_direction*y_speed;

  rect(x,y,30,30);

  if(x>300-30 || x<0){
    x_direction=x_direction*-1;

  }

  if(y>300-30 || y<0 ){
    y_direction=y_direction*-1;

  }

}

//object2
void DrawObject2(){

  i=i+i_direction*i_speed;
  j=j+j_direction*j_speed;

  rect(j,i,50,50);

  if(i>300-50 || i<0){
    i_direction=i_direction*-1;

  }

  if(j>300-50 || j<0 ){
    j_direction=j_direction*-1;

  }

}

< back to sketch