void setup(){
size(370, 350);
frameRate(1);
}
void draw(){
background(#000000);
draw_battery(count, 80, 100, 100);
count++;
if(count==6) count = 1;
}
void draw_battery(int charge, int posX, int posY, int stretch){
//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));
}
No comments:
Post a Comment