ICC
< back to sketch

float x1,x2,x3,x4,x5;
float y1,y2,y3,y4,y5;
float x1_speed,x2_speed,x3_speed ,y1_speed,y2_speed,y3_speed;
float mouse_speed;
float px,qx,dx,deg;
float py,qy,dy;
float speed=30.0;

int x1_direction;
int y1_direction;
int x2_direction;
int y2_direction;
int x3_direction;
int y3_direction;
int x4_direction;
int y4_direction;

void setup(){
  size(300,300);
  x1_direction=1;
  y1_direction=1;
  x2_direction=1;
  y2_direction=1;
  x3_direction=1;
  y3_direction=1;
  x4_direction=1;
  y4_direction=1;
  x1_speed=mouseX/10;
  y1_speed=1.8;
  x2_speed=mouseY/random(10);
  y2_speed=3.6;
  x3_speed=2.1;
  y3_speed=3.9;
  x1=width/2;
  y1=width/2;
  x2=width/2;
  y2=width/2;
  x3=width/2;
  y3=width/2;
  x4=150;
  y4=150;
  x5=mouseX;
  y5=mouseY;
  qx=50;
  qy=50;

}

void loop(){

  px=mouseX;
  py=mouseY;
  dx=qx-px;
  dy=qy-py;

  deg=sqrt(dx*dx+dy*dy);//get a distance bectween q-p
  if(deg>0){
    qx -= dx/speed;
    qy -= dy/speed;
  }
  
  x5=mouseX;
  y5=mouseY;
  background(0,0,0);

  ellipseMode(CENTER_DIAMETER);
  rectMode(CENTER_DIAMETER);
  //shikaku
  fill(0,0,0);
  stroke(46,152,255);
  rect(150,150,150,150);

  ellipseMode(CENTER_DIAMETER);
  //sennoaidanomaru
  ellipse(75,75,10,10);
  ellipse(225,75,10,10);
  ellipse(225,225,10,10);
  ellipse(75,225,10,10);
  //ookinamaru
  strokeWeight(1);
  fill(255,255,255);
  ellipse(150,150,x4*1.5,y4*1.5);
  ellipse(150,150,x4*1.5-1,y4*1.5-1);
  ellipse(150,150,x4*1.5-2,y4*1.5-2);
  //chugurainomaru
  strokeWeight(1);
  stroke(211,255,0);
  fill(x5,y5,255);
  ellipse(qx,qy,x4*2/5,y4*2/5);
  //tiisaimaru
  stroke(244,0,0);
  fill(255,0,25);
  ellipse(qx,qy,5,5);

  x1_speed=mouseX/10;
  x2_speed=mouseY/10;
  x1=x1+x1_direction*x1_speed;
  y1=y1+y1_direction*y1_speed;

  x2=x2+x2_direction*x2_speed;
  y2=y2+y2_direction*y2_speed;

  x3=x3+x3_direction*x3_speed;
  y3=y3+y3_direction*y3_speed;

  x4=mouseX;
  y4=mouseY;

  stroke(x1,y1,255);
  ellipseMode(CENTER_DIAMETER);
  rectMode(CENTER_DIAMETER);
  noFill();
  ellipse(mouseX,mouseY,20,20);
  ellipse(x1,y1,60,60);
  noFill();
  rect(x2,y2,20,20);
  noFill();
  rect(x3,y3,10,10);

  line(mouseX,mouseY,x1,y1);
  line(x1,y1,x2,y2);
  line(x2,y2,x3,y3);

  if(x1>270||x1<30) {
    x1_direction=x1_direction*-1;
  }

  if(y1>270||y1<30) {
    y1_direction=y1_direction*-1;
  }

  if(x2>290||x2<0) {
    x2_direction=x2_direction*-1;
  }

  if(y2>290||y2<0) {
    y2_direction=y2_direction*-1;
  }

  if(x3>295||x3<0) {
    x3_direction=x3_direction*-1;
  }

  if(y3>295||y3<0) {
    y3_direction=y3_direction*-1;
  }
  if(x4==150) {
    x4=0;
  }
  if(x4<150) {
    x4=x4+((300-x4)-x4);
  }
  if(y4==150) {
    y4=0;
  }
  if(y4<150) {
    y4=y4+((300-y4)-y4);
  }

}

< back to sketch