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

lab2bat

  int calculate=0;
  int wide=200;
  int high=100;
  int posX =50;
  int posY =125;
void setup(){
  frameRate(100);
  size(350,350);
}

void draw(){
  background(0);
  strokeWeight(2);
  stroke(255);
  fill(0);
  rect(posX , posY , 200 , 100);
  rect(posX+200 , posY+25 , 25 , 50);
  Energy();
  noStroke();
  fill(255);
  positive(posX+175,posY+45,15);
  negative(posX+15,posY+45,15);
//text
  fill(255);
  textSize(50);
  float percentBat = (wide/200)*100;
  text((int)(percentBat)+" %",posX+75,posY+150);
}

void positive(int posX,int posY,int S){
    rect(posX+(S/3),posY, S/3 ,S);
    rect(posX,posY+(S/3), S,S/3);
}

void negative(int posX,int posY,int S){
    rect(posX+(S/3),posY, S/3 ,S);
}

void Energy(){
  fill(0,255,0);
  noStroke();
  rect(posX , posY , wide  ,high);
  wide = (wide-1)%wide;
}

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

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