วันเสาร์ที่ 5 กันยายน พ.ศ. 2558

Lab3_Battery

Battery Charging



int space;
int value=1;
void setup() {
  size(500, 500);
}
void draw() {
  frameRate(30);
  background(255);//white
  battery(80, 140);
  space=space+value;
  if (space==300) {
    value=0;
    value=value-1;
  } else if (space==0&&value<0) {
    value=0;
    value=value+1;
  }
  int percent=(space*100)/300;
  textSize(50);
  fill(random(255), random(255), random(255));//rainbow color
  text((int)percent+"%", 210, 400);
  if (percent<10&&value==1) {
    text("Charging", 130, 100);
  }
  if (percent>95) {
    text("Full", 200, 100);
  }
}

void battery(int countX, int countY) {
  int w=300;//width
  int h=120;//height
  stroke(0);//dark blue
  strokeWeight(4);
  fill(255);//white

  //big square
  rect(countX, countY, w, h);
  fill(255);//white
  //batt head
  rect(countX+300, countY+35, w/9, h-70);
  //batt symbol
  strokeWeight(10);
  // + symbol
  line(countX+350, countY-50, countX+350, countY+10);
  line(countX+320, countY-20, countX+380, countY-20);
  /// - Symbol
  line(countX-60, countY-20, countX-10, countY-20);
  //battery quntity
  strokeWeight(2);
  if (space>0) {
    fill(#DD0000);
  }
  if (space>70) {
    fill(#F5ED00);
  }
  if (space>230) {
    fill(#69E376);
  }
  rect(countX, countY, space, h);//#1 batt
}


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

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