/
polygon.pde
51 lines (43 loc) · 1004 Bytes
/
polygon.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class polygon {
PVector[] points = new PVector[3];
color c;
polygon() {
setRandom();
}
void setRandom() {
for (int i=0; i<points.length; i++) {
points[i] = new PVector( random(ww), random(hh) );
}
c = randomColor();
}
void alter() {
for (int i=0; i<points.length; i++) {
alterVector(points[i]);
}
}
void alterColor() {
float r = red(c)+random(-5,5);
float g = green(c)+random(-5,5);
float b = blue(c)+random(-5,5);
float a = alpha(c)+random(-5,5);
if (r>255) { r=255; } else if (r<0) { r=0; }
if (g>255) { g=255; } else if (g<0) { g=0; }
if (b>255) { b=255; } else if (b<0) { b=0; }
if (a>150) { a=150; } else if (a<50) { a=50; }
c = color(r, g, b, a);
}
polygon deepCopy() {
polygon newPol = new polygon();
for(int i=0; i<newPol.points.length; i++) {
newPol.points[i] = points[i].copy();
}
newPol.c = c;
return newPol;
}
void draw() {
fill(c);
beginShape();
for (PVector v:points) { vertex(v.x, v.y); }
endShape(CLOSE);
}
}