Lab3 - FlyingBird



void setup() {
  size(530, 530);
  frameRate(60);
}
float global_BX, global_BY, global_BL, global_BW;
void draw() {
  background(#87CEFA);
  Cloud();
  Body(width/2, height/2, width*3/16, height*3/16);
  motion_bird(3);
  motion_cloud();
}
void Body(float BX, float BY, float BL, float BW) {
  global_BX=BX; //Bird_X
  global_BY=BY; //Bird_Y
  global_BL=BL; //Bird_Lenght
  global_BW=BW; //Bird_Width
  stroke(#8B7355);
  fill(#DEB887);
  strokeWeight(5);
  ellipse(width/2, height/2, width*3/16, height*3/16);


  bezier(BX+BL/6, BY-BW/6, BX+BL*2/3, BY-BW/2, BX+BL*2/3, BY-BW/2+End_R/3, BX*14/8, BY+End_R);
  //line(BX+BL/6, BY-BW/6, BX+BL*2/3, BY-BW/2);
  //line(BX+BL*2/3, BY-BW/2,BX*14/8, BY);
  bezier(BX-BL/6, BY-BW/6, BX-BL*2/3, BY-BW/2, BX-BL*2/3, BY-BW/2+End_R/3, BX*2/8, BY+End_R);
  //line(BX+BL/6, BY-BW/6, BX*14/8, BY+End_R);
  //line(BX-BL/6, BY-BW/6, BX*2/8, BY+End_R);

  strokeWeight(3);
  ellipse(BX, BY, BL/2, BW/2);
  fill(#8B7355);
  ellipse(BX-BL/18, BY-BW/13, BL/50, BW/50);
  ellipse(BX+BL/18, BY-BW/13, BL/50, BW/50);

  noFill();
  beginShape();
  vertex(BX-BL/10, BY);
  vertex(BX, BY+BW/7);
  vertex(BX+BL/10, BY);
  endShape();
}
float End_R=0;
boolean Ending_R=false;
void motion_bird(int speed) {
  if (mouseButton == LEFT)speed+=2;
  else if (mouseButton == RIGHT)speed-=2;
  if (End_R<-global_BW/3)Ending_R=true;
  else if (End_R>global_BW/3)Ending_R=false;

  if (Ending_R)End_R+=speed;
  else if (!Ending_R)End_R-=speed;
}
void Cloud() {
  noStroke();
  fill(255);
  ellipse(width*3/16+motion_C1, height*3/16, width*5/16, height*2/16); //Cloud 1
  ellipse(width*12/16+motion_C2, height*5/16, width*7/16, height*3/16); //Cloud 2
  ellipse(width*2/16+motion_C3, height*11/16, width*8/16, height*5/16); //Cloud 3
  ellipse(width*15/16+motion_C4, height*13/16, width*13/16, height*6/16); //Cloud 4
}
boolean limitC1X, limitC2X, limitC3X, limitC4X;
float motion_C1, motion_C2, motion_C3, motion_C4;

void motion_cloud() {
  if (motion_C1<-width*0.3/16)limitC1X=true;
  else if (motion_C1>width*0.3/16)limitC1X=false;
  if (limitC1X)motion_C1+=0.05;
  else motion_C1-=0.05;

  if (motion_C2<-width*0.5/16)limitC2X=true;
  else if (motion_C2>width*0.5/16)limitC2X=false;
  if (limitC2X)motion_C2+=0.15;
  else motion_C2-=0.15;

  if (motion_C3<-width*1/16)limitC3X=true;
  else if (motion_C3>width*1/16)limitC3X=false;
  if (limitC3X)motion_C3+=0.33;
  else motion_C3-=0.33;

  if (motion_C4<-width*1/16)limitC4X=true;
  else if (motion_C4>width*1/16)limitC4X=false;
  if (limitC4X)motion_C4+=0.55;
  else motion_C4-=0.55;
}


Lab3 - Song



void setup() {
  size(580, 580);
  smooth();
  strokeWeight(3);
  frameRate(60);
  background(255);
  scope();
}

void draw() {
  fill(255);
  ellipse(width/2, height/2, width*3/4, height*3/4);
  text_bodyslam(0, 2);
  crow(0, 2);
  Cloud();
  tear();
}

void text_bodyslam(float textX, float textY) {

  float RT=width/16;   //ratio text
  textFont(createFont("Tahoma", 38));
  String t = "Body Slam";
  fill(0);
  text(t, (RT)*5.5+RT*textX, (RT)*13+RT*textY);
}

void crow(float PositionX, float PositionY) {
  float RC=width/16; //ratio crow
  stroke(0);
  fill(0);

  //body//
  line(RC*6.5+RC*PositionX, RC*5+RC*PositionY, RC*6.65+RC*PositionX, RC*5.5+RC*PositionY);
  bezier(RC*9+RC*PositionX, RC*3.01+RC*PositionY, RC*8+RC*PositionX, RC*2.5+RC*PositionY,
    RC*7+RC*PositionX, RC*3+RC*PositionY, RC*6.5+RC*PositionX, RC*5.01+RC*PositionY);
  bezier(RC*6.65+RC*PositionX, RC*5.5+RC*PositionY, RC*6+RC*PositionX, RC*6+RC*PositionY,
    RC*5.75+RC*PositionX, RC*7+RC*PositionY, RC*5.75+RC*PositionX, RC*7.5+RC*PositionY);
  line(RC*5.75+RC*PositionX, RC*7.5+RC*PositionY, RC*6+RC*PositionX, RC*7.25+RC*PositionY);
  bezier(RC*6+RC*PositionX, RC*7.25+RC*PositionY, RC*6+RC*PositionX, RC*8+RC*PositionY,
    RC*6.8+RC*PositionX, RC*8.6+RC*PositionY, RC*7+RC*PositionX, RC*9+RC*PositionY);


  //pen//
  line(RC*9.0+RC*PositionX, RC*3.0+RC*PositionY, RC*10.0+RC*PositionX, RC*3.1+RC*PositionY);
  bezier(RC*10+RC*PositionX, RC*3.1+RC*PositionY, RC*9.5+RC*PositionX, RC*3.25+RC*PositionY,
    RC*9.15+RC*PositionX, RC*3.15+RC*PositionY, RC*9+RC*PositionX, RC*3.5+RC*PositionY);
  bezier(RC*9+RC*PositionX, RC*3.5+RC*PositionY, RC*9.2+RC*PositionX, RC*3.4+RC*PositionY,
    RC*9.5+RC*PositionX, RC*3.45+RC*PositionY, RC*10+RC*PositionX, RC*3.55+RC*PositionY);
  noFill();
  bezier(RC*10+RC*PositionX, RC*3.55+RC*PositionY, RC*9.25+RC*PositionX, RC*3.7+RC*PositionY,
    RC*8.8+RC*PositionX, RC*4.35+RC*PositionY, RC*8.8+RC*PositionX, RC*5.25+RC*PositionY);
  fill(0);
  bezier(RC*8.8+RC*PositionX, RC*5.25+RC*PositionY, RC*10.2+RC*PositionX, RC*6.75+RC*PositionY,
    RC*10.1+RC*PositionX, RC*8+RC*PositionY, RC*10+RC*PositionX, RC*9+RC*PositionY);

  //tail//
  beginShape();
  vertex(RC*10+RC*PositionX, RC*9+RC*PositionY);
  vertex(RC*11.25+RC*PositionX, RC*10.75+RC*PositionY);
  vertex(RC*10.75+RC*PositionX, RC*10.5+RC*PositionY);
  vertex(RC*10.95+RC*PositionX, RC*10.8+RC*PositionY);
  vertex(RC*10.25+RC*PositionX, RC*10.5+RC*PositionY);
  vertex(RC*10.35+RC*PositionX, RC*10.75+RC*PositionY);
  vertex(RC*9.3+RC*PositionX, RC*9.8+RC*PositionY);

  endShape();


  //leg//
  beginShape();
  vertex(RC*7+RC*PositionX, RC*9+RC*PositionY);
  vertex(RC*7.5+RC*PositionX, RC*10+RC*PositionY);
  vertex(RC*7+RC*PositionX, RC*11.1+RC*PositionY);
  vertex(RC*7.3+RC*PositionX, RC*11.1+RC*PositionY);
  vertex(RC*8+RC*PositionX, RC*10+RC*PositionY);
  vertex(RC*7.8+RC*PositionX, RC*9.5+RC*PositionY);
  vertex(RC*8.7+RC*PositionX, RC*10.2+RC*PositionY);
  vertex(RC*8.5+RC*PositionX, RC*11.1+RC*PositionY);
  vertex(RC*8.8+RC*PositionX, RC*11.1+RC*PositionY);
  vertex(RC*9.3+RC*PositionX, RC*9.8+RC*PositionY);


  endShape();
  strokeWeight(3);
  beginShape();
  vertex(RC*6.5+RC*PositionX, RC*5+RC*PositionY);
  vertex(RC*6.65+RC*PositionX, RC*5.5+RC*PositionY);
  vertex(RC*5.75+RC*PositionX, RC*7.5+RC*PositionY);
  vertex(RC*6+RC*PositionX, RC*7.25+RC*PositionY);
  vertex(RC*7+RC*PositionX, RC*9+RC*PositionY);
  vertex(RC*9.3+RC*PositionX, RC*9.8+RC*PositionY);
  vertex(RC*10+RC*PositionX, RC*9+RC*PositionY);
  vertex(RC*8.8+RC*PositionX, RC*5.25+RC*PositionY);

  vertex(RC*9+RC*PositionX, RC*3.5+RC*PositionY);
  vertex(RC*10+RC*PositionX, RC*3.1+RC*PositionY);
  vertex(RC*9.0+RC*PositionX, RC*3.0+RC*PositionY);

  endShape();

  beginShape();
  vertex(RC*8.8+RC*PositionX, RC*5.25+RC*PositionY);
  bezierVertex(RC*8.8+RC*PositionX, RC*4.35+RC*PositionY, RC*9.25+RC*PositionX, RC*3.7+RC*PositionY,
    RC*10+RC*PositionX, RC*3.55+RC*PositionY);
  vertex(RC*9+RC*PositionX, RC*3.5+RC*PositionY);
  endShape();

  ellipse(RC*7.8+RC*PositionX, RC*11.1+RC*PositionY, 130, 10);
}
void Cloud() {
  noStroke();
  fill(#828282);
  beginShape();
  vertex(width*14/16, height*2.5/16);
  curveVertex(width*16/16, height*2.5/16);
  curveVertex(width*13/16, height*1/16);
  curveVertex(width*12/16, height*1/16);
  curveVertex(width*10/16, height*2/16);
  curveVertex(width*9/16, height*1.5/16);
  curveVertex(width*7/16, height*1/16);
  curveVertex(width*6/16, height*2/16);
  curveVertex(width*4.5/16, height*1.5/16);
  curveVertex(width*2.5/16, height*2.5/16);
  curveVertex(width*3.5/16, height*4.0/16);
  curveVertex(width*6/16, height*4.5/16);
  curveVertex(width*7.5/16, height*4/16);
  curveVertex(width*10/16, height*4/16);
  curveVertex(width*12/16, height*3.5/16);
  curveVertex(width*14/16, height*3/16);
  curveVertex(width*14/16, height*2.5/16);
  endShape();
}
void scope() {
  //ratio scope
  int Color=0;
  for (float pos=width*2; pos>width*3/4; pos--) {
    stroke(0);
    if (pos<=width*5/4) {
      stroke(Color, Color, Color);
      Color++;
    }
    noFill();
    ellipse(width/2, height/2, pos, pos);
  }
}
float fallY=0, bigger=0, taller=0;
boolean rain_on=false;
void tear() {
  if (mouseButton == LEFT)rain_on=true;
  else if (mouseButton == RIGHT)rain_on=false;
  if (rain_on) {
    bigger+=0.1;
    taller+=0.2;
    fallY+=3;

    float Yfalling=height*5.5/16+fallY;
    float TBigger=width*5/580+bigger;
    if (Yfalling>=height*13.5/16) {
      taller=1;
      Yfalling=height*13.5/16;
    }
    if (TBigger>width*30/580)TBigger=width*30/580;

    noStroke();
    fill(#87CEFF);
    ellipse(width*8.5/16, Yfalling, TBigger, height*5/580+taller);
  } else if (!rain_on) {
    bigger=0;
    taller=0;
    fallY=0;
  }
}

Lab3 - Book



float Rx, Ry;

void setup() {
  size(580, 580);
  smooth();
  strokeWeight(3);
  frameRate(60);
}

float LineL, LineR;
int up;


void draw() {
  if (keyPressed){
    if (key == 'u' || key == 'U') {
      up++;
      if (up>=8)up=8;
    }
    else if (key == 'd' || key == 'D') {
    up--;
    if (up<=-8)up=-8;}}

  //ratioq
  Rx=1;
  Ry=1;
  float R=width/16;
  background(#8B4513);
  Book_background();
  Secret_Box(width*8/580, height*8/580-up, 1, 1);

  Write_Text();
}


void Secret_Box(float X, float Y, float Rx, float Ry) {
  float R=width/16;
  X=X-8;
  Y=Y-9;
  TX=X;
  TY=Y;

  //Biggest box
  stroke(0);
  fill(#EEEED1);
  quad((R)*4*Rx +R*X, (R)*7.5*Ry +R*Y,
    (R)*12*Rx +R*X, (R)*7.5*Ry +R*Y,
    (R)*12*Rx +R*X, (R)*10.5*Ry +R*Y,
    (R)*4*Rx +R*X, (R)*10.5*Ry +R*Y );

  //Left//
  fill(#FFD700);
  quad((R)*3.8*Rx +R*X, (R)*7.6*Ry +R*Y, //0001
    (R)*4*Rx +R*X, (R)*7.6*Ry +R*Y,
    (R)*4*Rx +R*X, (R)*10.4*Ry +R*Y,
    (R)*3.8*Rx +R*X, (R)*10.4*Ry +R*Y );

  quad((R)*3.5*Rx +R*X, (R)*7.7*Ry +R*Y, //0010
    (R)*3.8*Rx +R*X, (R)*7.7*Ry +R*Y,
    (R)*3.8*Rx +R*X, (R)*10.3*Ry +R*Y,
    (R)*3.5*Rx +R*X, (R)*10.3*Ry +R*Y );

  quad((R)*3.3*Rx +R*X, (R)*7.6*Ry +R*Y, //0100
    (R)*3.5*Rx +R*X, (R)*7.6*Ry +R*Y,
    (R)*3.5*Rx +R*X, (R)*10.4*Ry +R*Y,
    (R)*3.3*Rx +R*X, (R)*10.4*Ry +R*Y );

  quad((R)*3.1*Rx +R*X, (R)*7.8*Ry +R*Y, //1000
    (R)*3.3*Rx +R*X, (R)*7.8*Ry +R*Y,
    (R)*3.3*Rx +R*X, (R)*10.2*Ry +R*Y,
    (R)*3.1*Rx +R*X, (R)*10.2*Ry +R*Y );

  fill(#8B6914);  //<<1000
  quad((R)*2.9*Rx +R*X, (R)*8*Ry +R*Y,
    (R)*3.1*Rx +R*X, (R)*8*Ry +R*Y,
    (R)*3.1*Rx +R*X, (R)*10*Ry +R*Y,
    (R)*2.9*Rx +R*X, (R)*10*Ry +R*Y );

  bezier((R)*2.9*Rx +R*X, (R)*8*Ry +R*Y,
    (R)*2.5*Rx +R*X, (R)*9*Ry +R*Y,
    (R)*2.5*Rx +R*X, (R)*9*Ry +R*Y,
    (R)*2.9*Rx +R*X, (R)*10*Ry +R*Y );


  //Right//
  fill(#FFD700);
  quad((R)*12*Rx +R*X, (R)*7.6*Ry +R*Y, //1000
    (R)*12.2*Rx +R*X, (R)*7.6*Ry +R*Y,
    (R)*12.2*Rx +R*X, (R)*10.4*Ry +R*Y,
    (R)*12*Rx +R*X, (R)*10.4*Ry +R*Y );

  quad((R)*12.2*Rx +R*X, (R)*7.7*Ry +R*Y, //0100
    (R)*12.5*Rx +R*X, (R)*7.7*Ry +R*Y,
    (R)*12.5*Rx +R*X, (R)*10.3*Ry +R*Y,
    (R)*12.2*Rx +R*X, (R)*10.3*Ry +R*Y );

  quad((R)*12.5*Rx +R*X, (R)*7.6*Ry +R*Y, //0010
    (R)*12.7*Rx +R*X, (R)*7.6*Ry +R*Y,
    (R)*12.7*Rx +R*X, (R)*10.4*Ry +R*Y,
    (R)*12.5*Rx +R*X, (R)*10.4*Ry +R*Y );

  quad((R)*12.7*Rx +R*X, (R)*7.8*Ry +R*Y, //0001
    (R)*12.9*Rx +R*X, (R)*7.8*Ry +R*Y,
    (R)*12.9*Rx +R*X, (R)*10.2*Ry +R*Y,
    (R)*12.7*Rx +R*X, (R)*10.2*Ry +R*Y );

  fill(#8B6914);
  quad((R)*12.9*Rx +R*X, (R)*8*Ry +R*Y, //0001>>
    (R)*13.1*Rx +R*X, (R)*8*Ry +R*Y,
    (R)*13.1*Rx +R*X, (R)*10*Ry +R*Y,
    (R)*12.9*Rx +R*X, (R)*10*Ry +R*Y );

  bezier((R)*13.1*Rx +R*X, (R)*8*Ry +R*Y,
    (R)*13.5*Rx +R*X, (R)*9*Ry +R*Y,
    (R)*13.5*Rx +R*X, (R)*9*Ry +R*Y,
    (R)*13.1*Rx +R*X, (R)*10*Ry +R*Y );

  //Mid//
  for (LineL=5; LineL<=11; LineL++) {
    if (LineL<8)
      line((R)*LineL*Rx +R*X, (R)*7.5*Ry +R*Y,
        (R)*LineL*Rx +R*X, (R)*10.5*Ry +R*Y );
    else if (LineL>8)
      line((R)*LineL*Rx +R*X, (R)*7.5*Ry +R*Y,
        (R)*LineL*Rx +R*X, (R)*10.5*Ry +R*Y );
    else line((R)*LineL*Rx +R*X, (R)*7.5*Ry +R*Y,
      (R)*LineL*Rx +R*X, (R)*10.5*Ry +R*Y );
  }
}
boolean end_X, end_Y;

void motion(float Motion_X, float Motion_Y) {

  if (LineL>=2.7)end_X=true;
  else if (LineL<-2.7)end_X=false;
  if (LineR>=2)end_Y=true;
  else if (LineR<1.5)end_Y=false;

  if (!end_X)
    LineL=LineL+Motion_X;
  else if (end_X)
    LineL=LineL-Motion_X;

  if (!end_Y)
    LineR=LineR+Motion_Y;
  else if (end_Y)
    LineR=-Motion_Y;
}

void Book_background() {
  //Bg 222 184 135//
  //G 255 231 186//

  stroke(#EEAD0E);
  fill(#8B4513);
  rect(20, 20, 540, 540);

  fill(#FFE7BA);
  rect(50, 50, 480, 480);
  //tone
  float ColorC=222;
  float ColorD=184;
  float ColorE=135;
  float ColorB=479;
  for (int A=51; A<150; A++) {
    if (ColorC<=255) {
      ColorC++;
    }
    if (ColorD<=231) {
      ColorD=ColorD+1.5;
    }
    if (ColorE<=186) {
      ColorE=ColorE+1.5;
    }
    stroke(ColorC, ColorD, ColorE);
    ColorB=ColorB-2;
    rect(A, A, ColorB, ColorB);
  }
}
float TX, TY;
void Write_Text() {
  float R=width/16;
  // Andalus//
  textFont(createFont("Andalus", R));
  String Q ="Secrets of the Millionaire Mind";
  fill(#8B4500);
  text(Q, (R)*1.7, (R)*5);

  textFont(createFont("Andalus", R));
  String W ="T. Harv Eker";
  fill(#CD950C);
  text(W, (R)*5.5, (R)*13);

  textFont(createFont("Tahoma", R));  //10,000,000
  W ="1";
  fill(#CD950C);
  text(W, (R)*4.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  W ="0";
  text(W, (R)*5.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*6.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*7.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*8.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*9.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*10.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
  text(W, (R)*11.23*Rx +R*TX, (R)*9.25*Ry +R*TY );
}

Lab3 - Movie



float X, Y;

void setup() {

  size(580, 580);
  smooth();
  strokeWeight(3);
  frameRate(60);
}

boolean end_X, end_Y;
void draw() {
  background(0);
  DragonBall(mouseX, mouseY);
}

void DragonBall(float Rx, float Ry) {

  //Value Move//referent point (270,270)
  Rx=Rx-270;
  Ry=Ry-270;
  //outside shadow
  noStroke();
  X=380;
  Y=38;
  for (int A=0; A<=380; A++) {
    fill(A);

    ellipse(280+Rx, 490+Ry, X, Y);
    X--;
    Y=Y-0.1;
  }

  //Big stroke
  stroke(#FF7F00);
  fill(#FFD700);
  ellipse(270+Rx, 270+Ry, 450, 450);

  //background tone
  int ColorB=215;
  for (int posA=400; posA>230; posA--) {
    stroke(255, ColorB, 15);
    ColorB--;
    ellipse(255+Rx, 255+Ry, posA, posA);
  }

  //pure orange
  noStroke();
  fill(#FF8C00);
  ellipse(255+Rx, 255+Ry, 330, 330);

  //inside Shadow
  ColorB=255;
  int C=255;
  for (int posA=280; posA>100; posA--) {
    stroke(255, ColorB, C);
    ColorB--;
    C=C-2;
    ellipse(222+Rx, 222+Ry, posA, posA);

    noStroke();
    fill(#FF8C00);
    ellipse(250+Rx, 250+Ry, 230, 230);
  }
  RSX=Rx;
  RSY=Ry;
  Star(35, 70);
}
float RSX, RSY;

void Star(int Star_width, int Star_height) {
  float StartX;
  float StartY;

  //Star 1 //L up
  StartX = 210+RSX;
  StartY = 185+RSY;

  fill(#CD3700);
  stroke(#CD3700);
  beginShape();
  vertex(StartX, StartY); // Start
  vertex(StartX+(Star_width*0.25), StartY+(Star_height*0.375));
  vertex(StartX+Star_width, StartY+(Star_height*0.375));  //vertex 2  Right
  vertex(StartX+(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX+(Star_width*0.75), StartY+Star_height);          //vertex 3  Right
  vertex(StartX, StartY+(Star_height*0.75)); // mid
  vertex(StartX-(Star_width*0.75), StartY+Star_height);          //vertex 4  Left
  vertex(StartX-(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX-Star_width, StartY+(Star_height*0.375));  //vertex 5  Left
  vertex(StartX-(Star_width*0.25), StartY+(Star_height*0.375));

  endShape(CLOSE);

  //Star 2  //R up
  StartX = 320+RSX;
  StartY = 185+RSY;


  fill(#CD3700);
  stroke(#CD3700);
  beginShape();
  vertex(StartX, StartY); // Start
  vertex(StartX+(Star_width*0.25), StartY+(Star_height*0.375));
  vertex(StartX+Star_width, StartY+(Star_height*0.375));  //vertex 2  Right
  vertex(StartX+(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX+(Star_width*0.75), StartY+Star_height);          //vertex 3  Right
  vertex(StartX, StartY+(Star_height*0.75)); // mid
  vertex(StartX-(Star_width*0.75), StartY+Star_height);          //vertex 4  Left
  vertex(StartX-(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX-Star_width, StartY+(Star_height*0.375));  //vertex 5  Left
  vertex(StartX-(Star_width*0.25), StartY+(Star_height*0.375));

  endShape(CLOSE);

  //Star 3 //L down
  StartX = 235+RSX;
  StartY = 295+RSY;


  fill(#CD3700);
  stroke(#CD3700);
  beginShape();
  vertex(StartX, StartY); // Start
  vertex(StartX+(Star_width*0.25), StartY+(Star_height*0.375));
  vertex(StartX+Star_width, StartY+(Star_height*0.375));  //vertex 2  Right
  vertex(StartX+(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX+(Star_width*0.75), StartY+Star_height);          //vertex 3  Right
  vertex(StartX, StartY+(Star_height*0.75)); // mid
  vertex(StartX-(Star_width*0.75), StartY+Star_height);          //vertex 4  Left
  vertex(StartX-(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX-Star_width, StartY+(Star_height*0.375));  //vertex 5  Left
  vertex(StartX-(Star_width*0.25), StartY+(Star_height*0.375));

  endShape(CLOSE);

  //Star 4 // R down
  StartX = 345+RSX;
  StartY = 295+RSY;

  fill(#CD3700);
  stroke(#CD3700);
  beginShape();
  vertex(StartX, StartY); // Start
  vertex(StartX+(Star_width*0.25), StartY+(Star_height*0.375));
  vertex(StartX+Star_width, StartY+(Star_height*0.375));  //vertex 2  Right
  vertex(StartX+(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX+(Star_width*0.75), StartY+Star_height);          //vertex 3  Right
  vertex(StartX, StartY+(Star_height*0.75)); // mid
  vertex(StartX-(Star_width*0.75), StartY+Star_height);          //vertex 4  Left
  vertex(StartX-(Star_width/2), StartY+(Star_height*0.625));
  vertex(StartX-Star_width, StartY+(Star_height*0.375));  //vertex 5  Left
  vertex(StartX-(Star_width*0.25), StartY+(Star_height*0.375));

  endShape(CLOSE);
}

Lab3 - Battery



void setup() {
  background(#191970);
  size(580, 580);
  smooth();
  strokeWeight(3);
  frameRate(60);
}

float V_BX=0, H_BY=0, BL=0, BW=0;
boolean end_X=false, end_Y=false;
void draw() {
  background(0);
  motion(0.03, 0.05);
  charge();
  Draw_Battery(V_BX, H_BY, BL, BW);
  Status();
}

void Draw_Battery(float V_BX, float H_BY, float BL, float BW) {

  //ratio//
  float BR=height/8;

  //X vertical V_BX;
  //Y horizontal  H_BY;

  //Length//BL;
  //Width//BW;

  noFill();
  stroke(255);
  //Big rectangle//
  rect(BR*2.5 + BR * V_BX,
    BR*3.5 + BR * H_BY,
    BR*3 + BR * BW,
    BR*1 + BR * BL);



  //small rectangle//
  rect(BR*5.5  + BR*V_BX  + BR*BW,
    BR*3.75 + BR*H_BY  + BR*1/4*BL,
    BR*0.15 + 0.15 * BR*BW,
    BR*0.5  + 0.5 * BR*BL);
  //color small rect//

  fill(#CCCCCC);
  rect(BR*5.5  + BR*V_BX  + BR*BW,
    BR*3.75 + BR*H_BY  + BR*1/4*BL,
    BR*0.15 + 0.15 * BR*BW,
    BR*0.5  + 0.5 * BR*BL);


  //capacity
  if (Cap_Battery>=1) {
    strokeWeight(1);
    stroke(255);
    fill(#FFFF33);
    rect((BR*2.5 + BR * V_BX),
      BR*3.5 + BR * H_BY,
      BR*1 + BR * BW/3,
      BR*1 + BR * BL);
  }

  if (Cap_Battery>=2) {
    fill(#99FF33);
    rect((BR*2.5 + BR * V_BX)+(BR*2.5 )*2/5 + BR*BW *1/3,
      BR*3.5 + BR * H_BY,
      BR*1 + BR * BW/3,
      BR*1 + BR * BL);
  }

  if (Cap_Battery>=3) {
    fill(#33FF33);
    rect((BR*2.5 + BR * V_BX)+(BR*2.5 )*4/5 + BR*BW *2/3,
      BR*3.5 + BR * H_BY,
      BR*1 + BR * BW/3,
      BR*1 + BR * BL);
  }

  Positive(V_BX*8, H_BY*8, BL*8, BW*8);
  Negative(V_BX*8, H_BY*8, BL*8, BW*8);
}

void Positive(float V_SX, float H_SY, float SL, float SW) {
  //ratio
  float PR=height/64;
  //X vertical//
  V_SX=V_SX+38+SW;
  //Y horizontal//
  H_SY=H_SY+28+SL/2;
  //Length//
  SL=SL/8;
  //Width//
  SW=SW/8;

  fill(#FF3333);
  noStroke();
  beginShape();
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*2.5 + PR*H_SY -0.5*PR*SW); //L 1
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*2.5 + PR*H_SY -0.5*PR*SW); //R 1
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*3.5 + PR*H_SY -0.25*PR*SW); //R 2
  vertex(PR*5.5 + PR*V_SX +0.5*PR*SL, PR*3.5 + PR*H_SY -0.25*PR*SW); //R 3
  vertex(PR*5.5 + PR*V_SX +0.5*PR*SL, PR*4.5 + PR*H_SY +0.25*PR*SW); //R 4
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*4.5 + PR*H_SY +0.25*PR*SW); //R 5
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*5.5 + PR*H_SY +0.5*PR*SW); //R 6
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*5.5 + PR*H_SY +0.5*PR*SW); //L 6
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*4.5 + PR*H_SY +0.25*PR*SW); //L 5
  vertex(PR*2.5 + PR*V_SX -0.5*PR*SL, PR*4.5 + PR*H_SY +0.25*PR*SW); //L 4
  vertex(PR*2.5 + PR*V_SX -0.5*PR*SL, PR*3.5 + PR*H_SY -0.25*PR*SW); //L 3
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*3.5 + PR*H_SY -0.25*PR*SW); //L 2

  endShape();
}

void Negative(float V_SX, float H_SY, float SL, float SW) {
  //ratio
  float PR=height/64;
  //X vertical//
  V_SX=V_SX+18;
  //Y horizontal//
  H_SY=H_SY+28+SL/2;
  //Length//
  SL=SL/8;
  //Width//
  SW=SW/8;

  fill(#FF3333);
  noStroke();
  beginShape();
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*2.5 + PR*H_SY -0.5*PR*SW); //L 1
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*2.5 + PR*H_SY -0.5*PR*SW); //R 1
  vertex(PR*4.5 + PR*V_SX +0.25*PR*SL, PR*5.5 + PR*H_SY +0.5*PR*SW); //R 6
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*5.5 + PR*H_SY +0.5*PR*SW); //L 6
  vertex(PR*3.5 + PR*V_SX -0.25*PR*SL, PR*2.5 + PR*H_SY -0.5*PR*SW); //L 1


  endShape();
}

float Cap_Battery=0;
void charge() {
  if (Cap_Battery<=0)Cap_Battery=0;
  if (Cap_Battery<=2) {
    fill(random(255), random(255), random(188));
    textSize(88);
    text("Charge", width/4, height/4);
  }
  if (Cap_Battery>0)Cap_Battery-=0.008;
}

void mouseClicked() {
  Cap_Battery++;
  if (Cap_Battery>=3.9)Cap_Battery=3.9;
}
float limit;
float limit_Above(float on, float off) {
  if (Cap_Battery<=2)limit=on;
  else if (Cap_Battery>2)limit=off;
  return limit;
}

void motion(float Motion_X, float Motion_Y) {


  if (V_BX>=2.5)end_X=true;
  else if (V_BX<-2.5)end_X=false;
  if (H_BY>=3.5)end_Y=true;
  else if (H_BY<-limit_Above(1.3, 3.5))end_Y=false;

  if (!end_X)
    V_BX=(V_BX+Motion_X);
  else if (end_X)
    V_BX=V_BX-Motion_X;

  if (!end_Y)
    H_BY=(H_BY+Motion_Y);
  else if (end_Y)
    H_BY=H_BY-Motion_Y;
}

void Status() {
  fill(255);
  textSize(13);
  if (Cap_Battery<=2)text("Status : warning", width/38, height/38);
  else if (Cap_Battery>2)text("Status : Discharge", width/38, height/38);
  else text("Status : Error", width/38, height/38);
}