@@ -31,27 +31,25 @@ def calculate(nn)
3131 # Render landscape as grid of quads
3232 def render
3333 # Every cell is an individual quad
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
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 ( 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
5553 end
5654 end
5755end
0 commit comments