Remarks: Processing Mazes

From Maze

(Difference between revisions)
Jump to: navigation, search
Line 15:Line 15:
With the ability to further define the graphics, the code became longer with the enhanced precision:
With the ability to further define the graphics, the code became longer with the enhanced precision:
−
<source lang="java">
+
size(1020, 680);
−
size(1020, 680);
+
noStroke();
−
+
background(0, 0, 255);
−
noStroke();
+
int rows = int(pow(2, int(random(1, 6)))); // 2, 4, 8, 16, 32
−
background(0, 0, 255);
+
int thickness = int(pow(2, int(random(1, 4)))); // 2, 4, 8
−
+
int unit = height / (rows + 4);
−
int rows = int(pow(2, int(random(1, 6)))); // 2, 4, 8, 16, 32
+
int uthick = unit / thickness;
−
int thickness = int(pow(2, int(random(1, 4)))); // 2, 4, 8
+
int uthicker = unit + uthick;
−
int unit = height / (rows + 4);
+
for (int x = int(-unit * 0.75); x < width+unit; x += unit) {
−
int uthick = unit / thickness;
+
for (int y = height/2 - rows/2 * unit; y < height/2 + rows/2 * unit; y += unit) {
−
int uthicker = unit + uthick;
+
if (random(1) > 0.5) {
−
+
fill(255);
−
for (int x = int(-unit * 0.75); x < width+unit; x += unit) {
+
quad(x, y, x + unit, y + unit, x + uthicker, y + unit, x + uthick, y);
−
for (int y = height/2 - rows/2 * unit; y < height/2 + rows/2 * unit; y += unit) {
+
}
−
if (random(1) > 0.5) {
+
else {
−
fill(255);
+
fill(0);
−
quad(x, y, x + unit, y + unit, x + uthicker, y + unit, x + uthick, y);
+
quad(x, y + unit, x + unit, y, x + uthicker, y, x + uthick, y + unit);
−
}
+
}
−
else {
 
−
fill(0);
 
−
quad(x, y + unit, x + unit, y, x + uthicker, y, x + uthick, y + unit);
 
}
}
}
}
−
}
+
−
</source>
 
[1] In the C language two plus symbols "++" is a shortcut for adding one. For example x++ adds the value 1 to the variable x. The "++" in C++ is a reference to this operator.
[1] In the C language two plus symbols "++" is a shortcut for adding one. For example x++ adds the value 1 to the variable x. The "++" in C++ is a reference to this operator.

Revision as of 19:55, 27 May 2011

View this revision of Remarks: Processing Mazes.

Personal tools