-
Notifications
You must be signed in to change notification settings - Fork 3
/
OvershotGenerator.pde
267 lines (190 loc) · 4.76 KB
/
OvershotGenerator.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
int warps = 780;
int dim_cell = 5;
int height = 15*dim_cell;
int[] pattern_code;
int[] pattern_width;
int ndx = 0;
int [][] stitches;
int [][] shaft_c; //0 = white, 1 == brown, 2 == red;
boolean parse = false;
int[] command;
String error;
void setup() {
println("setup");
//REPLACE THIS WITH A LARGER OR SMALLER WINDOW AS YOU NEED
//the best way to calculate is to input the value of warps multiplied by the value of dim_cell
size(3920, 350);
background(255);
error = "";
command = new int[2];
pattern_code = new int[width];
pattern_width = new int[width];
shaft_c = new int[6][2];
shaft_c[0][0] = 0;
shaft_c[0][1] = 1;
shaft_c[1][0] = 0;
shaft_c[1][1] = 1;
shaft_c[2][0] = 2;
shaft_c[2][1] = 1;
shaft_c[3][0] = 2;
shaft_c[3][1] = 0;
shaft_c[4][0] = 2;
shaft_c[4][1] = 1;
shaft_c[5][0] = 2;
shaft_c[5][1] = 0;
stitches = new int[8][2];
//A
stitches[0][0] = 0;
stitches[0][1] = 1;
//B
stitches[1][0] = 2;
stitches[1][1] = 3;
//C
stitches[2][0] = 1;
stitches[2][1] = 0;
//D
stitches[3][0] = 4;
stitches[3][1] = 5;
//E
stitches[4][0] = 5;
stitches[4][1] = 3;
//F
stitches[5][0] = 2;
stitches[5][1] = 1;
//G
stitches[6][0] = 3;
stitches[6][1] = 5;
//H
stitches[7][0] = 4;
stitches[7][1] = 0;
}
void draw() {
background(255);
int x = dim_cell;
int count = 0;
for (int i = 0; i < ndx; i++) {
int code = pattern_code[i];
int pw = pattern_width[i];
// println(code+" "+pw);
fill(0);
noStroke();
textSize(12);
char c = (char) (code + 'a');
text(c+""+pw, x, dim_cell*2);
for (int j = 0; j < pw; j++) {
count++;
//cycle through the pattern
int pw_ndx = j % 2;
int active_shaft = stitches[code][pw_ndx];
//draw the shaft array
for(int k = 5; k >= 0; k--){
stroke(0);
if(k == active_shaft) fill(0);
else fill(255);
int y = dim_cell*2+(dim_cell*6 -dim_cell*k);
rect(x, y, dim_cell, dim_cell);
}
//draw the color mapping
for(int k = 5; k >= 0; k--){
//draw top color
noStroke();
fill(getColor(shaft_c[active_shaft][0]));
rect(x, dim_cell*10+dim_cell*k, dim_cell, dim_cell*3);
//draw bottom color
noStroke();
fill(getColor(shaft_c[active_shaft][1]));
rect(x, (dim_cell*19+dim_cell*k), dim_cell, dim_cell*3);
}
x += dim_cell;
}
}
noFill();
stroke(0);
rect(dim_cell, dim_cell*10, 780*dim_cell, dim_cell*18);
// println(code+" "+pw);
fill(0);
noStroke();
textSize(12);
text("count: "+count, x, dim_cell*30);
// println(code+" "+pw);
fill(255, 0, 0);
noStroke();
textSize(12);
text(error, x, dim_cell*31);
}
color getColor(int x){
if(x == 0) return color(255);
if(x == 1) return color(161, 139, 127);
return color(255, 0, 0);
}
boolean isPlainSet(int c){
if(c == 0 || c == 1 || c==4 || c== 5) return true;
return false;
}
//this compares against the last value for width
boolean commandValid(){
if(ndx == 0) return true;
int c = command[0];
int lc = pattern_code[ndx-1];
int lw = pattern_width[ndx-1];
int e = lw % 2;
if(e == 0 ){
if(isPlainSet(lc) && isPlainSet(c)) return true;
if(!isPlainSet(lc) && !isPlainSet(c)) return true;
}else{
if(isPlainSet(lc) && !isPlainSet(c)) return true;
if(!isPlainSet(lc) && isPlainSet(c)) return true;
}
return false;
}
void printStats(){
int[] counts;
counts = new int[6];
for(int i = 0; i< 6; i++){
counts[i] = 0;
}
for(int i = 0; i < ndx; i++){
int code = pattern_code[i];
int pw = pattern_width[i];
for (int j = 0; j < pw; j++) {
//cycle through the pattern
int pw_ndx = j % 2;
int active_shaft = stitches[code][pw_ndx];
counts[active_shaft]++;
}
char c = (char) (code + 'a');
println(c+""+pw);
}
for(int i = 0; i<6; i++){
println("shaft "+(i+1)+": "+counts[i]);
}
}
void keyPressed() {
if(key == ENTER){
save("canvas.jpg");
printStats();
}
if(key == BACKSPACE){
println("DELETE");
if(ndx > 0) ndx--;
}
if (key >= 'a' && key <= 'z') {
command[0] = (int) (key - 'a');
if(commandValid()){
error = "";
}else{
error = "Invalid Code Entered 1";
}
}
if(key >= '1' && key <= '9'){
command[1] = (int) (key - '0');
if(commandValid()){
error = "";
pattern_code[ndx] = command[0];
pattern_width[ndx] = command[1];
ndx++;
}else{
error = "Invalid Code Entered 2";
}
}
}