-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForme.pde
165 lines (142 loc) · 2.98 KB
/
Forme.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class Forme implements Comparable {
final static int POINT = 0;
final static int RECT = 1;
final static int TRIANGLE = 2;
final static int STAR = 3;
final static int ELLIPSE = 4;
final static int CIRCLE = 5;
final static int SQUARE = 6;
int t; // type
float x, y; // coordinates: X, Y
float w, h; // size: width, height
color c; // color
float r; // rotation
float ch, cs, cb, ca; // hue, saturation, brightness, alpha
// Constructor
Forme(int it, float ix, float iy, float iw, float ih, color ic, float ir) {
t = it;
x = ix;
y = iy;
w = iw;
h = ih;
c = ic;
r = ir;
//color components
ch = hue(c);
cs = saturation(c);
cb = brightness(c);
ca = alpha(c);
}
void draw() {
pushMatrix();
translate(x,y);
rotate(radians(r));
c = color(ch, cs, cb, ca);
fill(c);
noStroke();
switch(t) {
case ELLIPSE:
ellipse(0,0,w,h);
break;
case CIRCLE:
ellipse(0,0,w,w);
break;
case SQUARE:
rect(-w/2,-w/2,w,w);
break;
case RECT:
rect(-w/2,-h/2,w,h);
break;
case TRIANGLE:
triangle(0,-w,
w*cos(PI*30/180),
w*sin(PI*30/180),
-w*cos(PI*30/180),
w*sin(PI*30/180));
break;
case STAR:
drawStar(0,0,w/2,w,5);
break;
default:
stroke(c);
point(x, y);
}
popMatrix();
}
private void drawStar ( float x, float y, float radius_inner, float radius_outer, int spikes ) {
float r = 0.0;
float res = 360.0/spikes;
float res_half = res/2;
beginShape();
for ( float i = 0; i < 360; i+=res ) {
r = -HALF_PI + radians( i );
vertex( x + cos(r) * radius_outer, y + sin(r) * radius_outer );
r = -HALF_PI + radians( i + res_half );
vertex( x + cos(r) * radius_inner, y + sin(r) * radius_inner );
}
endShape( CLOSE );
}
void drawSeamless() {
translate(-width, -height);
draw();
translate(width, 0);
draw();
translate(width, 0);
draw();
translate(-2*width, height);
draw();
translate(width, 0);
draw();
translate(width, 0);
draw();
translate(-2*width, height);
draw();
translate(width, 0);
draw();
translate(width, 0);
draw();
translate(-width, -height);
}
void setPosition(float ix, float iy) {
x = ix;
y = iy;
}
void setSize(float iw, float ih) {
w = iw;
h = ih;
}
void setType(int it) {
t = it;
}
void setHue(float h) {
ch = h;
}
void setSaturation(float s) {
cs = s;
}
void setBrightness(float b) {
cb = b;
}
void setOpacity(float a) {
ca = a;
}
void setRotation(float ir) {
r = ir;
}
float getMinSize() {
return min(w,h);
}
public int compareTo(Object f) {
float size = getMinSize();
float fsize = ((Forme) f).getMinSize();
if(size < fsize) {
return 1;
}
else if (size == fsize) {
return 0;
}
else {
return -1;
}
}
}