|
1 | 1 | # The Nature of Code |
2 | 2 | # Daniel Shiffman |
3 | | -# https://natureofcode.com |
| 3 | +# http://natureofcode.com |
4 | 4 |
|
5 | 5 | # "Landscape" example |
6 | 6 | class Landscape |
@@ -31,25 +31,27 @@ def calculate(nn) |
31 | 31 | # Render landscape as grid of quads |
32 | 32 | def render |
33 | 33 | # Every cell is an individual quad |
34 | | - # using the propane grid convenience function instead of a nested loop |
35 | | - grid(z.size - 1, z[0].size - 1) do |x, y| |
36 | | - # one quad at a time |
37 | | - # each quad's color is determined by the height value at each vertex |
38 | | - # (clean this part up) |
39 | | - no_stroke |
40 | | - push_matrix |
41 | | - begin_shape(Processing::QUADS) |
42 | | - translate(x * scl - w * 0.5, y * scl - h * 0.5, 0) |
43 | | - fill(z[x][y] + 127, 220) |
44 | | - vertex(0, 0, z[x][y]) |
45 | | - fill(z[x + 1][y] + 127, 220) |
46 | | - vertex(scl, 0, z[x + 1][y]) |
47 | | - fill(z[x + 1][y + 1] + 127, 220) |
48 | | - vertex(scl, scl, z[x + 1][y + 1]) |
49 | | - fill(z[x][y + 1] + 127, 220) |
50 | | - vertex(0, scl, z[x][y + 1]) |
51 | | - end_shape |
52 | | - pop_matrix |
| 34 | + # (could use quad_strip here, but produces funny results, investigate this) |
| 35 | + (0...z.size - 1).each do |x| |
| 36 | + (0...z[0].size - 1).each do |y| |
| 37 | + # one quad at a time |
| 38 | + # each quad's color is determined by the height value at each vertex |
| 39 | + # (clean this part up) |
| 40 | + no_stroke |
| 41 | + push_matrix |
| 42 | + begin_shape(QUADS) |
| 43 | + translate(x * scl - w * 0.5, y * scl - h * 0.5, 0) |
| 44 | + fill(z[x][y] + 127, 220) |
| 45 | + vertex(0, 0, z[x][y]) |
| 46 | + fill(z[x + 1][y] + 127, 220) |
| 47 | + vertex(scl, 0, z[x + 1][y]) |
| 48 | + fill(z[x + 1][y + 1] + 127, 220) |
| 49 | + vertex(scl, scl, z[x + 1][y + 1]) |
| 50 | + fill(z[x][y + 1] + 127, 220) |
| 51 | + vertex(0, scl, z[x][y + 1]) |
| 52 | + end_shape |
| 53 | + pop_matrix |
| 54 | + end |
53 | 55 | end |
54 | 56 | end |
55 | 57 | end |
0 commit comments