33require 'propane'
44require 'toxiclibs'
55# Test and SimplexNoise Karsten Schmidt
6- # Better to use Built in OPenSimplex2 in propane
6+ # Better to use Built in OpenSimplex2 in propane
77class SimplexNoiseTest < Propane ::App
88 attr_reader :noise_dimension , :noise_offset
99
1010 NS = 0.06 # (try from 0.005 to 0.5)
11- KEYS = %w( 1 2 3 4 ) . freeze
11+ KEYS = ( 1 .. 4 ) . map { | i | i . to_s }
1212 def settings
1313 size 300 , 300 , P2D
1414 end
@@ -22,26 +22,24 @@ def setup
2222
2323 def draw
2424 background 0
25- ( 0 ...width ) . each do |i |
26- ( 0 ...height ) . each do |j |
27- noise_val = 0
28- case ( noise_dimension )
29- when KEYS [ 0 ]
30- noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , 0 )
31- when KEYS [ 1 ]
32- noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset )
33- when KEYS [ 2 ]
34- noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset , frame_count * 0.01 )
35- when KEYS [ 3 ]
36- noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset , 0 , frame_count * 0.01 )
37- else
38- noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , 0 )
39- end
40- c = ( noise_val * 127 + 128 ) . to_i
41- # Fix required to return a java signed int
42- col = Java ::Monkstone ::ColorUtil . hex_long ( c << 16 | c << 8 | c | 0xff000000 )
43- pixels [ j * width + i ] = col # this is more efficient than set
25+ grid ( width , height ) do |i , j |
26+ noise_val = 0
27+ case ( noise_dimension )
28+ when KEYS [ 0 ]
29+ noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , 0 )
30+ when KEYS [ 1 ]
31+ noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset )
32+ when KEYS [ 2 ]
33+ noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset , frame_count * 0.01 )
34+ when KEYS [ 3 ]
35+ noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , j * NS + noise_offset , 0 , frame_count * 0.01 )
36+ else
37+ noise_val = Toxi ::SimplexNoise . noise ( i * NS + noise_offset , 0 )
4438 end
39+ c = ( noise_val * 127 + 128 ) . to_i
40+ # Fix required to return a java signed int
41+ col = Java ::Monkstone ::ColorUtil . hex_long ( c << 16 | c << 8 | c | 0xff000000 )
42+ pixels [ j * width + i ] = col # this is more efficient than set
4543 end
4644 update_pixels
4745 @noise_offset += NS / 2
0 commit comments