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

LAB 3 Battery with warning

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

void draw() {
  background(0);
  draw_positive_negative(160,50);
  battery(100,250);

}

//function for make battery
void battery(int X,int Y) {
  noStroke();
  fill(255);
  body(X, Y);
  energy(X, Y);
}

//=======make fucntion draw positive and negative======
void draw_positive_negative(int X,int Y){
  fill(255);
  rect_vertical(X, Y);
  rect_horizon(X, Y);
  rect_horizon(X, Y+550);
}

//=====make body battery=======
void body(int X, int Y) {
  rect(X+60, Y+80, 180, 250);
  rect(X+105, Y+30, 90, 50);
}

// ====make variable in global=====
int colour=0; //change colour
int limit_colour=0; //for limit value colour and resize energy

//======make energy=====
void energy(int X, int Y) {
  chang_colour();
 
  stroke(0+(colour*2), 150, 255-(colour*2));
  noFill();
  rect(X+70, Y+100, 160, 220);
 
  noStroke();
  fill(0+(colour*2), 150, 255-(colour*2));
  rect(X+70, Y+100+limit_colour, 160, 220-limit_colour);
 
  warning(250,500);
}

//======make function for warning=========
void warning(int X,int Y) {
  if (limit_colour>=80&&limit_colour%10!=0) {
    textSize(30);
    fill(255, 0, 0);
    text("Warning", 190, 550);
    ellipse(X, Y-80, 20, 100);
    ellipse(X, Y, 10, 10);
  }
}


// ====make change clour and turn down or up energy======
void chang_colour() {
  if ((mouseButton==LEFT&&limit_colour>0)&&((mouseX>=160&&mouseX<=420)&&(mouseY>=50&&mouseY<=250))) {
    colour--;
    limit_colour--;
  }
  if ((mouseButton==LEFT&&limit_colour<=200)&&((mouseX>=160&&mouseX<=420)&&(mouseY>=500&&mouseY<=700))) {
    colour++;
    limit_colour++;
  }
}


//======make function for draw rect vertical======
void rect_vertical(int X, int Y) {
  noStroke();
  rect(X+60, Y, 60, 180);
}

//======make function for draw rect horizon=====
void rect_horizon(int X, int Y) {
  noStroke();
  rect(X, Y+60, 180, 60);
}

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

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