วันจันทร์ที่ 17 สิงหาคม พ.ศ. 2558

LAB 1 งานชิ้นที 2 Battery

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

int x=5; //x is value of start point in x line
int y=10; //y is value of start point in y line
int sizeFront=0;//sizeFront is value for plus size text
int limit_X_line=1;//limit for move in X line
int limit_Y_line=1;//limit for move in y line
int upSize=0;//value for upsize battery

void draw(){
background(0);

stroke(255);
fill(255);


//body
rect(x+50,y+0,upSize+100,upSize+50);
stroke(0);
rect(x+20,y+50,upSize+160,upSize+250);

//energy
fill(0,150,0);
rect(x+25,y+55,upSize+150,(upSize/8)+30);
fill(0,170,0);
rect(x+25,(upSize/8)+y+90,upSize+150,(upSize/8)+30);
fill(0,190,0);
rect(x+25,((upSize/8)*2)+y+125,upSize+150,(upSize/8)+30);
fill(0,220,0);
rect(x+25,((upSize/8)*3)+y+160,upSize+150,(upSize/8)+30);
fill(0,230,0);
rect(x+25,((upSize/8)*4)+y+195,upSize+150,(upSize/8)+30);
fill(0,240,0);
rect(x+25,((upSize/8)*5)+y+230,upSize+150,(upSize/8)+30);
fill(0,250,0);
rect(x+25,((upSize/8)*6)+y+265,upSize+150,(upSize/8)+30);

//text of %
fill(250,200,0);
textSize(sizeFront+30);
text("100%",x+65+(upSize/2),y+40);


// set up key for move
if(keyPressed){
  if((key == 'd'||key == 'D')&&limit_X_line<400)
  {
    x++;
    limit_X_line++;
  }
  if((key == 'a'|| key == 'A')&&limit_X_line>0)
  {
    x--;
    limit_X_line--;
  }

}

if(keyPressed){
  if((key == 's'||key == 'S')&&limit_Y_line<260)
  {
    y++;
    limit_Y_line++;
  }
  if((key == 'w'|| key == 'W')&&limit_Y_line>0)
  {
    y--;
    limit_Y_line--;
  }
}

// set key for resize
if ((mousePressed && (mouseButton == LEFT))&&upSize<40)
{
    upSize++;
  } else if ((mousePressed && (mouseButton == RIGHT))&&upSize>=0)
  {
    upSize--;
}



}
 

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

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