Skip to content

Commit 8afe787

Browse files
committed
moor exapmles
1 parent ca67bbd commit 8afe787

File tree

3 files changed

+72
-22
lines changed

3 files changed

+72
-22
lines changed

external_library/gem/toxiclibs/simulation/gray_scott_image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
class GrayScottToneImage < Propane::App
3838
attr_reader :gs, :tone_map, :img
3939

40-
KEYS = %w(1 2 3 4 5 6 7 8 9).freeze
40+
KEYS = (1..9).map { |i| i }
4141

4242
def setup
4343
sketch_title 'Gray Scott Image'
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# Test and SimplexNoise Karsten Schmidt
5+
# Better to use Built in OpenSimplex2 in propane
6+
class SimplexNoiseTest < Propane::App
7+
attr_reader :noise_dimension, :noise_offset
8+
9+
NS = 0.06 # (try from 0.005 to 0.5)
10+
KEYS = (1..4).map { |i| i.to_s }
11+
def settings
12+
size 300, 300, P2D
13+
end
14+
15+
def setup
16+
sketch_title 'Open Simplex Noise Test'
17+
@noise_dimension = KEYS[0]
18+
@noise_offset = 100
19+
load_pixels
20+
end
21+
22+
def draw
23+
background 0
24+
grid(width, height) do |i, j|
25+
noise_val = 0
26+
case(noise_dimension)
27+
when KEYS[0]
28+
noise_val = noise(i * NS + noise_offset, 0)
29+
when KEYS[1]
30+
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset)
31+
when KEYS[2]
32+
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset, frame_count * 0.01)
33+
when KEYS[3]
34+
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset, 0, frame_count * 0.01)
35+
else
36+
noise_val = noise(i * NS + noise_offset, 0)
37+
end
38+
c = (noise_val * 127 + 128).to_i
39+
# Fix required to return a java signed int
40+
col = Java::Monkstone::ColorUtil.hex_long(c << 16 | c << 8 | c | 0xff000000)
41+
pixels[j * width + i] = col # this is more efficient than set
42+
end
43+
update_pixels
44+
@noise_offset += NS / 2
45+
end
46+
47+
def key_pressed
48+
@noise_dimension = key if KEYS.include? key
49+
end
50+
end
51+
52+
SimplexNoiseTest.new

external_library/gem/toxiclibs/simulation/simplex_noise_test.rb

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
require 'propane'
44
require '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
77
class 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

Comments
 (0)