-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoptic.pde
190 lines (166 loc) · 5.87 KB
/
coptic.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
// Global parameters //<>// //<>//
int blockwidth = 50;
int blockheight = 75;
int numcols = 4;
int radius = 0;
int maxtwist = 8;
int yOffset = 0;
int yLength = 12;
Column[] columns = new Column[numcols];
void setup() {
smooth();
size(400, 900);
//fullScreen();
// Parameters go inside the parentheses when the object is constructed.
for (int i = 0; i < numcols; i = i+1) {
columns[i] = new Column(i, color(255, 255, 0), color(50, 100, 50), i*blockwidth, (2*numcols-i)*blockwidth, 0, yOffset*blockheight, yLength*blockheight-1);
println(columns[i].ypos, columns[i].yflipped, columns[i].yend, columns[i].yflippedend);
}
// noLoop();
}
void draw() {
for (int i = 0; i < numcols; i = i+1) {
columns[i].setTwist();
columns[i].step();
println(columns[i].ypos, columns[i].yflipped, columns[i].yend, columns[i].yflippedend);
if (columns[i].ypos < columns[i].yend) {
columns[i].leftDisplay();
columns[i].rightDisplay();
}
}
// noLoop();
}
void keyPressed() {
if (key == 'q') {
exit();
} else {
loop();
}
}
// Even though there are multiple objects, we still only need one class.
// No matter how many cookies we make, only one cookie cutter is needed.
class Column {
int index;
color BG, FG;
float xpos, xflipped, ypos, yflipped;
float xend, xflippedend, yend, yflippedend;
int twist;
int effectiveTwist;
boolean Zslash;
// The Constructor is defined with arguments.
Column(int tempIndex, color tempBG, color tempFG, float tempXpos, float tempXflipped, float tempYpos, float tempYflipped, float tempYend) {
index = tempIndex;
BG = tempBG;
FG = tempFG;
xpos = tempXpos;
xflipped = tempXflipped;
ypos = 2*tempYpos-tempYflipped-blockheight; //backup so that dummy fill doesn't show and one more for fencepost
yflipped = tempYpos-blockheight; //start dummy fill one before for fencepost
yflippedend = tempYend - tempYpos + tempYflipped + blockheight; //reverse backup so that dummy fill doesn't show and one more for fencepost
yend = tempYend + blockheight; //start dummy fill one (reverse before) for fencepost
twist = 0;
effectiveTwist = 0;
while (ypos < tempYpos-blockheight) {
Zslash = true;
step();
rightDisplay();
println(index, ypos, yflipped, yend, yflippedend);
Zslash = false;
step();
rightDisplay();
println(index, ypos, yflipped, yend, yflippedend);
}
}
float threshhold(int twistVal) {
return 0.5-(0.5/maxtwist)*twistVal;
}
int nbhdTwist(int radiusVal) {
int normTwist = 0;
for (int i = index - radiusVal; i <= index + radiusVal; i = i+1) {
normTwist = normTwist + abs(columns[(i % numcols + numcols) % numcols].twist); // compensate for stupid Java %
}
return normTwist*Integer.signum(twist);
}
void setTwist() {
effectiveTwist = nbhdTwist(radius);
if (random(0, 1)<threshhold(effectiveTwist)) {
Zslash = true;
twist = twist + 1;
} else {
Zslash = false;
twist = twist - 1;
}
}
void step() {
ypos = ypos + blockheight;
//if (ypos > height-blockheight) { // wrap to next set of columns
// xpos = xpos + (2*numcols+1)*blockwidth;
// ypos = 0;
//}
yflipped = yflipped + blockheight;
//if (yflipped > height-blockheight) { // wrap to next set of columns
// xflipped = xflipped + (2*numcols+1)*blockwidth;
// yflipped = 0;
//}
yend = yend - blockheight;
yflippedend = yflippedend - blockheight;
}
float Xadjusted(float X, float Y) {
float adjustedHeight = floor(height/blockheight)*blockheight;
return X + floor(Y/adjustedHeight) * (2*numcols+1)*blockwidth;
}
float Yadjusted(float X, float Y) {
float adjustedHeight = floor(height/blockheight)*blockheight;
return Y % adjustedHeight;
}
void leftDisplay() {
float xpos = Xadjusted(this.xpos, this.ypos);
float ypos = Yadjusted(this.xpos, this.ypos);
float xflipped = Xadjusted(this.xflipped, this.yflippedend);
float yflippedend = Yadjusted(this.xflipped, this.yflippedend);
fill(BG);
stroke(FG);
strokeWeight(1);
rect(xpos, ypos, blockwidth, blockheight);
rect(xflipped-blockwidth, yflippedend-blockheight, blockwidth, blockheight);
strokeWeight(4);
if (Zslash) {
line(xpos, ypos, xpos+blockwidth, ypos+blockheight);
line(xflipped, yflippedend, xflipped-blockwidth, yflippedend-blockheight);
} else {
line(xpos+blockwidth, ypos, xpos, ypos+blockheight);
line(xflipped-blockwidth, yflippedend, xflipped, yflippedend-blockheight);
}
fill(FG);
textSize(24);
textAlign(LEFT, BOTTOM);
text(str(twist), xpos, ypos+blockheight);
textAlign(RIGHT, BOTTOM);
//text(str(effectiveTwist), xpos+blockwidth, ypos+blockheight);
}
void rightDisplay() {
float xpos = Xadjusted(this.xpos, this.yend);
float yend = Yadjusted(this.xpos, this.yend);
float xflipped = Xadjusted(this.xflipped, this.yflipped);
float yflipped = Yadjusted(this.xflipped, this.yflipped);
fill(BG);
stroke(FG);
strokeWeight(1);
rect(xflipped-blockwidth, yflipped, blockwidth, blockheight);
rect(xpos, yend-blockheight, blockwidth, blockheight);
strokeWeight(4);
if (Zslash) {
line(xflipped, yflipped, xflipped-blockwidth, yflipped+blockheight);
line(xpos, yend, xpos+blockwidth, yend-blockheight);
} else {
line(xflipped-blockwidth, yflipped, xflipped, yflipped+blockheight);
line(xpos+blockwidth, yend, xpos, yend-blockheight);
}
fill(FG);
textSize(24);
textAlign(LEFT, TOP);
text(str(twist), xpos, yend-blockheight);
textAlign(RIGHT, BOTTOM);
//text(str(effectiveTwist), xpos+blockwidth, ypos+blockheight);
}
}