วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558

Lab 2 : Function Battary

 
int PercentBatt;

void setup(){
  size(600,500);
}

void draw(){
  background(#74A3FF);
int posX=100;
int posY=100;
  draw_battary(posX,posY);
  draw_positive(posX+450,posY);
  draw_nagative(posX-70,posY);
 
  textAlign(CENTER);                  //text
  textSize(40);
  fill(#ffffff);
  text(PercentBatt+" %", 200+posX,270+posY);
}


void mousePressed(){
  int increaseX;
 
  int count=PercentBatt;
  if(count<100){
  increaseX=10;
    PercentBatt = (PercentBatt + increaseX);
  }if(count>=100){
   PercentBatt =0;
  }
}


void draw_battary(int posX,int posY) {

  strokeWeight(10);                      //outside battary
  stroke(#ffffff);
  noFill();
  rect(posX,posY,400,200);

  rect(400+posX,45+posY,50,100);               //battery terminal

  noStroke();                               //energy of battary
  fill(#ffffff);
  rect(10+posX,10+posY,PercentBatt*3.8,180);
}

void draw_positive(int posX,int posY){
  rect(posX+10,posY, 10 ,30);
  rect(posX,posY+10, 30,10);
}

void draw_nagative(int posX,int posY){
  rect(posX,posY+10, 30,10);
}

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

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