//Battery 100%
int posX=80;
int posY=100;
int stretch=100;
int count=0;
boolean countUp = false;
boolean countDown =true;
void setup(){
size(370, 350);
frameRate(8);
}
void draw(){
background(#000000);
draw_battery(count);
if(mousePressed &&(mouseButton == LEFT)||countUp){
count++;
countUp = true;
countDown = false;
if(count >= 5){
count = 5;
countUp = false;
}
}
if(mousePressed &&(mouseButton == RIGHT)||countDown){
count--;
countDown = true;
if(count <= 0){
count = 0;
}
}
}
void draw_battery(int charge){
//Battery
stroke(#FFFFFF);
strokeWeight(4);
fill(86, 93, 119);
rect(posX, posY, stretch*2.2, stretch, 7);
rect(posX-(stretch*0.1), posY+(stretch*0.3), stretch*0.1, stretch*0.4);//minus
noStroke();
fill(#FFFFFF);
rect(posX+(stretch*2.4), posY+(stretch*0.5), stretch*0.3, stretch*0.1);//positive
noStroke();
fill(#FFFFFF);
rect(posX-(stretch*0.6), posY+(stretch*0.5), stretch*0.3, stretch*0.1);
rect(posX-(stretch*0.5), posY+(stretch*0.4), stretch*0.1, stretch*0.3);//Status
noStroke();
fill(76, 218 ,100);
if(charge>=1){//Status NUM1
rect(posX+(stretch*1.72), posY+(stretch*0.05), stretch*0.35, stretch*0.9, 7);
}
if(charge>=2){//Status NUM2
rect(posX+(stretch*1.32), posY+(stretch*0.05), stretch*0.35, stretch*0.9, 7);
}
if(charge>=3){//Status NUM3
rect(posX+(stretch*0.92), posY+(stretch*0.05), stretch*0.35, stretch*0.9, 7);
}
if(charge>=4){//Status NUM4
rect(posX+(stretch*0.52), posY+(stretch*0.05), stretch*0.35, stretch*0.9, 7);
}
if(charge>=5){//Status NUM5
rect(posX+(stretch*0.12), posY+(stretch*0.05), stretch*0.35, stretch*0.9, 7);
}
//TEXT
fill(#FFFFFF);
textSize((stretch*0.2));
text(charge*20+"% Charged",posX+(stretch*0.42),posY+(stretch*1.5));
//
if (count==0 && (frameCount%11)>2 && (frameCount%11)<18){
fill(#CD0000);
textSize((stretch*0.3));
text("Warning!", posX+(stretch*0.5), posY+(stretch*0.6));
}
}
No comments:
Post a Comment