3
3
require 'propane'
4
4
require 'toxiclibs'
5
5
# Test and SimplexNoise Karsten Schmidt
6
- # Better to use Built in OPenSimplex2 in propane
6
+ # Better to use Built in OpenSimplex2 in propane
7
7
class SimplexNoiseTest < Propane ::App
8
8
attr_reader :noise_dimension , :noise_offset
9
9
10
10
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 }
12
12
def settings
13
13
size 300 , 300 , P2D
14
14
end
@@ -22,26 +22,24 @@ def setup
22
22
23
23
def draw
24
24
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 )
44
38
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
45
43
end
46
44
update_pixels
47
45
@noise_offset += NS / 2
0 commit comments