วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558

Lab 3 : Battery

int posX=100;
int posY=100;
int y=25;
int h=100;
int paint;
int mouse;
int per=100;

void setup(){
 size(300,300);
 frameRate(10);
}


void draw(){
  background(#9B8B8B);
  draw_battery(posX,posY,60,h);
    if(h>0){
    h=h-1;
    paint=#FF0000;
    per=per-1;
   }
   if(h>40){
     paint=#FFF812;
   }
   if(h>80){
     paint=#24BF02;
   }
    if(h<10){
     draw_charge(190,150);
   }
   if(h==0){
     h=100;
     h=h+1;
     per=101;
     per=per-1;
   }

}

void draw_battery(int posX,int posY,int w,int h){

//strokeWeight();
fill(255);
rect(posX+10,posY+125,40,20);             //head battery
rect(posX-5,posY-5,70,130);           //battery
rect(posX-20,posY+150,20,5);           //positive and negative
rect(posX+60,posY+150,20,5);
rect(posX+68,posY+143,5,20);

textSize(20);
text(per+" %",posX,posY-25);

fill(paint);
rect(posX,posY,60,h);
}

void draw_charge(int x,int y){
  textSize(25);
  fill(#FF0000);
  text("Charge!",x,y);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น