Processing Code #Designing with Data
- Douglas Wang

- Aug 21, 2020
- 2 min read
int c1=50;
int c2=150;
int c3=150;
int c4=150;
int qy1 =470;
int qy2 =470;
int qy3 =470;
int qy4 =470;
int n=1;
int n1=0;
int n2=0;
int lx1=100;
int lx2=100;
int ly1=100;
int ly2=110;
int q1=50;
int q2=50;
int q3=50;
int r1=50;
int r2=50;
int r3=50;
void setup() {
background(0);
size(500, 500);
stroke(255);
strokeWeight(0);
fill(255);
circle(100, 70, 20); //center of the sun
triangle(100, 40, 90, 50, 110, 50); //triangles around the sun
triangle(100, 100, 90, 90, 110, 90);
triangle(70, 70, 80, 60, 80, 80);
triangle(130, 70, 120, 60, 120, 80);
stroke(c1);
fill(c1);
}
void draw() {
if (n<1) {
q1=q1+205;
}
stroke(70);
strokeWeight(5);
line(100, 105, 100, 400);
strokeWeight(0);
stroke(0);
fill(70);
quad(30, 340, 170, 340, 170, 349, 30, 349);
///////////////////////////Wire animation
strokeWeight(3);
stroke(255);
line(lx1, ly1, lx2, ly2);
if (ly1>350) {
lx1=100;
lx2=100;
ly1=100;
ly2=110;
c2=r1;
c3=r2;
c4=r3;
} else {
ly1=ly1+5;
ly2=ly2+5;
c2=50;
c3=50;
c4=50;
}
if (q3>255) {
r1=r1+50;
r2=r2+50;
r3=r3+50;
}
//////////////////////////////////////////Battery
fill(0);
stroke(70);
strokeWeight(4);
quad(20, 350, 60, 350, 60, 480, 20, 480);
quad(80, 350, 120, 350, 120, 480, 80, 480);
quad(140, 350, 180, 350, 180, 480, 140, 480);
///////////////////////////////////////////////Battery animation
fill(255);
strokeWeight(0);
quad(20, qy1, 60, qy1, 60, 480, 20, 480);
quad(80, qy2, 120, qy2, 120, 480, 80, 480);
quad(140, qy3, 180, qy3, 180, 480, 140, 480);
if (qy1<350) {
n=0;
n1=1;
} else
qy1=qy1-n;
if (qy2<350) {
n1=0;
n2=1;
q2=q2+205;
} else
qy2=qy2-n1;
if (qy3<350) {
n1=0;
n2=1;
q3=q3+205;
} else
qy3=qy3-n2;
/////////////////// red houses
stroke(c2, c3, c4);
fill(c2, c3, c4);
square(410, 55, 50);
square(200, 125, 50);
square(410, 195, 50);
square(270, 265, 50);
square(340, 335, 50);
square(200, 405, 50);
/////////////////////// white hosues G1
fill(q1);
square(200, 55, 50);
square(410, 125, 50);
square(340, 195, 50);
square(200, 265, 50);
square(410, 335, 50);
square(340, 405, 50);
/////////////////////// white hosues G2
fill(q2);
square(270, 55, 50);
square(340, 125, 50);
square(200, 195, 50);
square(340, 265, 50);
square(200, 335, 50);
square(270, 405, 50);
/////////////////////// white hosues G3
fill(q3);
square(340, 55, 50);
square(270, 125, 50);
square(270, 195, 50);
square(410, 265, 50);
square(270, 335, 50);
square(410, 405, 50);
//saveFrame();
}




Comments