Remarks: Processing Mazes

From Maze

(Difference between revisions)
Jump to: navigation, search
(Explain the Processing port)
(Addition of code)
Line 7:Line 7:
The first Processing version of 10 PRINT was written for the increased resolution of contemporary screens. It did this by making the thickness and ends of the lines into variables that can be changed while the program runs. The lines of the maze can range from 0.5 to 10 pixels wide and the lines can terminate with a rounded or square end. Like 10 PRINT, it maintained the grid of lines at 40 x 25 units, but unlike 10 PRINT it didn't add each grid unit in sequence, left to right and top to bottom, the entire grid was refreshed in unison. The color of the lines was set to white and the background to black, which gave the program a distinctly different feel from the original blues. The result is shown in figures ?? to ??.
The first Processing version of 10 PRINT was written for the increased resolution of contemporary screens. It did this by making the thickness and ends of the lines into variables that can be changed while the program runs. The lines of the maze can range from 0.5 to 10 pixels wide and the lines can terminate with a rounded or square end. Like 10 PRINT, it maintained the grid of lines at 40 x 25 units, but unlike 10 PRINT it didn't add each grid unit in sequence, left to right and top to bottom, the entire grid was refreshed in unison. The color of the lines was set to white and the background to black, which gave the program a distinctly different feel from the original blues. The result is shown in figures ?? to ??.
 +
The line endings are a subtle, but crucial change within this program. In the original 10 PRINT image (see fig ??), notice how each line terminates into a point. This is required because each of the 40 x 25 tiles that comprise the image are constrained to its 8 x 8 pixels area. This is is created by tiling these lines, fixed into their 64 pixels boxes. In the Processing program, each line is free to extend beyond and into the other lines area. This is because the lines are defined by x- and y-coordinates (precise locations on screen) rather than tile positions. Any number of shapes and colors can appear at any given pixel on screen.
 +
 +
The second Processing version of 10 PRINT took more liberties with the original program. Most importantly, the number of rows and columns in the grid could
 +
With the ability to further refine the graphics, the code because longer as more definition is required...
With the ability to further refine the graphics, the code because longer as more definition is required...
 +
int rows = int(pow(2, int(random(1, 6)))); // 2, 4, 8, 16, 32
 +
int thickness = int(pow(2, int(random(1, 4)))); // 2, 4, 8
 +
int unit = height / (rows + 4);
 +
int uthick = unit / thickness;
 +
int uthicker = unit + uthick;
 +
for (int x = int(-unit * 0.75); x < width+unit; x += unit) {
 +
for (int y = height/2 - rows/2 * unit; y < height/2 + rows/2 * unit; y += unit) {
 +
if (random(1) > 0.5) {
 +
fill(255);
 +
quad(x, y, x + unit, y + unit, x + uthicker, y + unit, x + uthick, y);
 +
}
 +
else {
 +
fill(0);
 +
quad(x, y + unit, x + unit, y, x + uthicker, y, x + uthick, y + unit);
 +
}
 +
}
 +
}
 +
[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:38, 27 May 2011

View this revision of Remarks: Processing Mazes.

Personal tools