int scale;
int energy = 1;
int colour = 0;
void setup() {
size(500, 500);
stroke(225);
}
void draw() {
background(0);
frameRate(25);
draw_battery(80, 140, 300, 120);
scale = scale+energy;
if (scale==300) {
energy = 0;
energy = energy-1;
draw_using();
}
if (scale==0 && energy < 0) {
energy = 0;
energy = energy+1;
draw_charging();
}
int per = (scale*100)/300;
if (per >= 80 ) {
colour = #008B00;
} else if (per < 80 && per > 20) {
colour = #FFFF00;
} else if (per <= 20) {
colour = #DD0000;
}
if (per == 0 || per == 1) {
draw_charging();
} else if (per == 99 || per == 100) {
draw_using();
}
fill(225);
textSize(50);
text((int)(per)+"%", 200, 400);
}
void draw_charging() {
fill(225);
textSize(50);
text("Charging", 150, 100);
}
void draw_using() {
fill(225);
textSize(50);
text("Using", 150, 100);
}
void draw_battery(int x, int y, int h, int w) {
strokeWeight(5);
fill(0);
rect(x+300, y+35, w/9, h-250);
fill(225);
rect(x, y, h, w);
fill(colour);
rect(x, y, scale, h-180);
line(x+250, y+25, x+250, y+85);
line(x+220, y+55, x+280, y+55);
line(x+20, y+55, x+70, y+55);
}
int energy = 1;
int colour = 0;
void setup() {
size(500, 500);
stroke(225);
}
void draw() {
background(0);
frameRate(25);
draw_battery(80, 140, 300, 120);
scale = scale+energy;
if (scale==300) {
energy = 0;
energy = energy-1;
draw_using();
}
if (scale==0 && energy < 0) {
energy = 0;
energy = energy+1;
draw_charging();
}
int per = (scale*100)/300;
if (per >= 80 ) {
colour = #008B00;
} else if (per < 80 && per > 20) {
colour = #FFFF00;
} else if (per <= 20) {
colour = #DD0000;
}
if (per == 0 || per == 1) {
draw_charging();
} else if (per == 99 || per == 100) {
draw_using();
}
fill(225);
textSize(50);
text((int)(per)+"%", 200, 400);
}
void draw_charging() {
fill(225);
textSize(50);
text("Charging", 150, 100);
}
void draw_using() {
fill(225);
textSize(50);
text("Using", 150, 100);
}
void draw_battery(int x, int y, int h, int w) {
strokeWeight(5);
fill(0);
rect(x+300, y+35, w/9, h-250);
fill(225);
rect(x, y, h, w);
fill(colour);
rect(x, y, scale, h-180);
line(x+250, y+25, x+250, y+85);
line(x+220, y+55, x+280, y+55);
line(x+20, y+55, x+70, y+55);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น