-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.pde
218 lines (175 loc) · 4.25 KB
/
Shape.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/** Shape
* Tracks graphical info
* Draws objects to screen
*/
public abstract class Shape {
// Variables
// Default
protected int[] DEF_STROKE = new int[]{255};
protected int[] DEF_FILL = new int[]{255};
protected float DEF_SIZE = 5;
// Instance
int[] stroke_info = DEF_STROKE;
int[] fill_info = DEF_FILL;
float size = DEF_SIZE;
// Abstract Methods
/** Make Shape
* Makes some shape around a given Point
* @param some Point in space
*/
abstract void make_shape(Point p);
// Functional Methods
/** Draw
* Sets global stroke and fill, then makes shape around some Point
* @param some Point in space
*/
void draw(Point p) {
apply_fill();
apply_stroke();
make_shape(p);
}
/** Apply fill
* Sets the global fill to this Shapes fill info using the fill method
*/
void apply_fill() {
switch (fill_info.length) {
// Grayscale
case 1:
fill(fill_info[0]);
break;
// Grayscale w/ alpha
case 2:
fill(fill_info[0],fill_info[1]);
break;
// RGB
case 3:
fill(fill_info[0],fill_info[1],fill_info[2]);
break;
// RGB w/ alpha
case 4:
fill(fill_info[0],fill_info[1],fill_info[2],fill_info[3]);
break;
// No fill
default:
noFill();
break;
}
}
/** Apply Stroke
* Sets the global stroke to this Shapes stroke info using the stroke method
*/
void apply_stroke() {
switch (stroke_info.length) {
// Grayscale
case 1:
stroke(stroke_info[0]);
break;
// Grayscale w/ alpha
case 2:
stroke(stroke_info[0],stroke_info[1]);
break;
// RGB
case 3:
stroke(stroke_info[0],stroke_info[1],stroke_info[2]);
break;
// RGB w/ alpha
case 4:
stroke(stroke_info[0],stroke_info[1],stroke_info[2],stroke_info[3]);
break;
// No stroke
default:
noStroke();
break;
}
}
/** Clear
* Sets the stroke and fill to empty
*/
void clear() {
set_no_stroke();
set_no_fill();
}
// Technical Methods
/** Copy
* Copies the stroke and fill of another Shape
* @param some Shape
*/
void copy(Shape s) {
set_stroke(s.get_stroke());
set_fill(s.get_fill());
}
// Setting fill
// No fill
void set_no_fill() {
this.fill_info = new int[]{};
}
// Copy fill
void set_fill(int[] in_fill) {
this.fill_info = in_fill;
}
// Default fill
void set_fill() {
this.fill_info = DEF_FILL;
}
// Grayscale
void set_fill(int b_w) {
this.fill_info = new int[]{b_w};
}
// Grayscale w/ alpha
void set_fill(int b_w,int alpha) {
this.fill_info = new int[]{b_w,alpha};
}
// RGB
void set_fill(int r, int g, int b) {
this.fill_info = new int[]{r,g,b};
}
// RGB w/ alpha
void set_fill(int r, int g, int b, int alpha) {
this.fill_info = new int[]{r,g,b,alpha};
}
// Get fill
int[] get_fill() {
return this.fill_info;
}
// Setting stroke
// No stroke
void set_no_stroke() {
this.stroke_info = new int[]{};
}
// Copy stroke
void set_stroke(int[] in_stroke) {
this.stroke_info = in_stroke;
}
// Default stroke
void set_stroke() {
this.stroke_info = DEF_STROKE;
}
// Grayscale
void set_stroke(int b_w) {
this.stroke_info = new int[]{b_w};
}
// Grayscale w/ alpha
void set_stroke(int b_w, int alpha) {
this.stroke_info = new int[]{b_w,alpha};
}
// RGB
void set_stroke(int r, int g, int b) {
this.stroke_info = new int[]{r,g,b};
}
// RGB w/ alpha
void set_stroke(int r, int g, int b, int alpha) {
this.stroke_info = new int[]{r,g,b,alpha};
}
// Get stroke
int[] get_stroke() {
return this.stroke_info;
}
// Getters/Setters
// Size
void set_size(float in_size) {
this.size = in_size < 1 ? this.size : in_size;
}
float get_size() {
return this.size;
}
}