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

Lab03 : Battery Charge/Uncharge

int wide=270, high=75;
float batt=225; //PERCENT TAB LENGTH
float percentB; //PERCENT
int dx=1; //DIRECTION OF PERCENT TAB -> '1' + , '0' -
void setup() {
  size(350, 250);
}
void draw() {
  int x=70;
  int y=110;
  String status;
  background(51);
  strokeWeight(4);
  stroke(0);
  // make battery charge/uncharge
  if (dx==1) {
    batt++;
    if (batt>225)batt=225;
  }
  if (dx==0) {
    batt--;
    if (batt<=0)batt=0;
  }
  percentB=batt/225*100;

  //Drawing
  draw_battery(x, y, wide, high);
  //INDICATE COLOR AND STATUS TEXT
  status="OK";
  if (percentB<=100) {
    fill(#3BC149);
    status="OK";  
    if (percentB<=80) {
      fill(#95FF03);
      status="Below 80%";
      if (percentB<=50) {
        fill(255, 0, 0); 
        status="Please Charge";
      }
    }
  }
  //DRAW PERCENTAB
  rect(x+(wide/12), y, batt, high); 
  textSize(30);
  text(int(percentB) + "% " + status, x, y-30); //PERCENT TEXT
  //DRAW + AND - SIGNS
  positive_sign(x+0.1*wide, y+0.4*high, 5);
  negative_sign(x+0.8*wide, y+0.4*high, 5);
}

void mousePressed() {
  if (mouseButton==LEFT) {
    dx=1;
  } else
  {
    dx=0;
  }
}



void draw_battery(int posX, int posY, int wide, int high) {
  fill(255); 
  //HEAD
  rect(posX, posY+(0.2*high), wide/12, high*3/5);
  //Body Battery
  rect(posX+(wide/12), posY, wide*5/6, high);
}

void positive_sign(float x, float y, int sizebox) {
  noStroke();
  fill(51, 0, 0);
  rect(x+sizebox, y, sizebox, sizebox);
  rect(x+2*sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+2*sizebox, sizebox, sizebox);
  rect(x, y+sizebox, sizebox, sizebox);
}

void negative_sign(float x, float y, int sizebox) {
  noStroke();
  fill(51, 0, 0);
  rect(x+2*sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+sizebox, sizebox, sizebox);
  rect(x, y+sizebox, sizebox, sizebox);
}


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

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

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...