Skip to content

Commit 6576c0d

Browse files
committed
example for new SimpleNoise functionality
1 parent 5b9f235 commit 6576c0d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Simplex Noise ###
2+
3+
Mainly inspired by Karsten Schmidt, Stefan Gustavson I created a `simplex_noise` library for propane (mainly in java) but tweeked the example to work in ruby. Read more from [Stefan Gustavson][simplex] who created the java code. Kudos to Karsten Schmidt for the test code (vanilla processing not ruby version)
4+
5+
[simplex]:http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: false
2+
require 'propane'
3+
# Test after Karsten Schmidt, SimplexNode after Stefan Gustavson
4+
class SimplexNoiseTest < Propane::App
5+
load_library :simplex_noise
6+
attr_reader :noise_dimension, :noise_offset
7+
8+
NS = 0.05 # (try from 0.005 to 0.5)
9+
10+
def settings
11+
size 200, 200, P2D
12+
end
13+
14+
def setup
15+
sketch_title 'Simplex Noise Test'
16+
@noise_dimension = 0
17+
@noise_offset = 100
18+
end
19+
20+
def draw
21+
background 0
22+
(0..width).each do |i|
23+
(0..height).each do |j|
24+
noise_val = 0
25+
case(noise_dimension)
26+
when 1
27+
noise_val = SimplexNoise.noise(i * NS + noise_offset, 0)
28+
when 2
29+
noise_val = SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset)
30+
when 3
31+
noise_val = SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, frame_count * 0.01)
32+
when 4
33+
noise_val = SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, 0, frame_count * 0.01)
34+
else
35+
noise_val = SimplexNoise.noise(i * NS + noise_offset, 0)
36+
end
37+
c = (noise_val * 127 + 128).to_i
38+
# Fix required to return a java signed int
39+
col = Java::Monkstone::ColorUtil.hex_long(c << 16 | c << 8 | c | 0xff000000)
40+
set(i, j, col)
41+
end
42+
end
43+
@noise_offset += NS / 2
44+
end
45+
46+
def key_pressed
47+
control_key = %w(1 2 3 4)
48+
@noise_dimension = key.to_i if control_key.include? key
49+
end
50+
end
51+
52+
SimplexNoiseTest.new

0 commit comments

Comments
 (0)