Remarks: Processing Mazes
From Maze
(Difference between revisions)
(Defining second Processing program) | |||
| 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: | ||
| − | size(1020, 680); | + | <source lang="java"> |
| − | noStroke(); | + | size(1020, 680); |
| − | background(0, 0, 255); | + | |
| − | int rows = int(pow(2, int(random(1, 6)))); // 2, 4, 8, 16, 32 | + | noStroke(); |
| − | int thickness = int(pow(2, int(random(1, 4)))); // 2, 4, 8 | + | background(0, 0, 255); |
| − | int unit = height / (rows + 4); | + | |
| − | int uthick = unit / thickness; | + | int rows = int(pow(2, int(random(1, 6)))); // 2, 4, 8, 16, 32 |
| − | int uthicker = unit + uthick; | + | int thickness = int(pow(2, int(random(1, 4)))); // 2, 4, 8 |
| − | for (int x = int(-unit * 0.75); x < width+unit; x += unit) { | + | int unit = height / (rows + 4); |
| − | for (int y = height/2 - rows/2 * unit; y < height/2 + rows/2 * unit; y += unit) { | + | int uthick = unit / thickness; |
| − | if (random(1) > 0.5) { | + | int uthicker = unit + uthick; |
| − | fill(255); | + | |
| − | quad(x, y, x + unit, y + unit, x + uthicker, y + unit, x + uthick, y); | + | 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) { |
| − | else { | + | if (random(1) > 0.5) { |
| − | fill(0); | + | fill(255); |
| − | quad(x, y + unit, x + unit, y, x + uthicker, y, x + uthick, y + unit); | + | 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); | ||
} | } | ||
} | } | ||
| − | + | } | |
| + | </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. | ||
