Skip to content

Commit

Permalink
moor exapmles
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Apr 5, 2021
1 parent ca67bbd commit 8afe787
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class GrayScottToneImage < Propane::App
attr_reader :gs, :tone_map, :img

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

def setup
sketch_title 'Gray Scott Image'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env jruby
# frozen_string_literal: true
require 'propane'
# Test and SimplexNoise Karsten Schmidt
# Better to use Built in OpenSimplex2 in propane
class SimplexNoiseTest < Propane::App
attr_reader :noise_dimension, :noise_offset

NS = 0.06 # (try from 0.005 to 0.5)
KEYS = (1..4).map { |i| i.to_s }
def settings
size 300, 300, P2D
end

def setup
sketch_title 'Open Simplex Noise Test'
@noise_dimension = KEYS[0]
@noise_offset = 100
load_pixels
end

def draw
background 0
grid(width, height) do |i, j|
noise_val = 0
case(noise_dimension)
when KEYS[0]
noise_val = noise(i * NS + noise_offset, 0)
when KEYS[1]
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset)
when KEYS[2]
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset, frame_count * 0.01)
when KEYS[3]
noise_val = noise(i * NS + noise_offset, j * NS + noise_offset, 0, frame_count * 0.01)
else
noise_val = noise(i * NS + noise_offset, 0)
end
c = (noise_val * 127 + 128).to_i
# Fix required to return a java signed int
col = Java::Monkstone::ColorUtil.hex_long(c << 16 | c << 8 | c | 0xff000000)
pixels[j * width + i] = col # this is more efficient than set
end
update_pixels
@noise_offset += NS / 2
end

def key_pressed
@noise_dimension = key if KEYS.include? key
end
end

SimplexNoiseTest.new
40 changes: 19 additions & 21 deletions external_library/gem/toxiclibs/simulation/simplex_noise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require 'propane'
require 'toxiclibs'
# Test and SimplexNoise Karsten Schmidt
# Better to use Built in OPenSimplex2 in propane
# Better to use Built in OpenSimplex2 in propane
class SimplexNoiseTest < Propane::App
attr_reader :noise_dimension, :noise_offset

NS = 0.06 # (try from 0.005 to 0.5)
KEYS = %w(1 2 3 4).freeze
KEYS = (1..4).map { |i| i.to_s }
def settings
size 300, 300, P2D
end
Expand All @@ -22,26 +22,24 @@ def setup

def draw
background 0
(0...width).each do |i|
(0...height).each do |j|
noise_val = 0
case(noise_dimension)
when KEYS[0]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, 0)
when KEYS[1]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset)
when KEYS[2]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, frame_count * 0.01)
when KEYS[3]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, 0, frame_count * 0.01)
else
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, 0)
end
c = (noise_val * 127 + 128).to_i
# Fix required to return a java signed int
col = Java::Monkstone::ColorUtil.hex_long(c << 16 | c << 8 | c | 0xff000000)
pixels[j * width + i] = col # this is more efficient than set
grid(width, height) do |i, j|
noise_val = 0
case(noise_dimension)
when KEYS[0]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, 0)
when KEYS[1]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset)
when KEYS[2]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, frame_count * 0.01)
when KEYS[3]
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, j * NS + noise_offset, 0, frame_count * 0.01)
else
noise_val = Toxi::SimplexNoise.noise(i * NS + noise_offset, 0)
end
c = (noise_val * 127 + 128).to_i
# Fix required to return a java signed int
col = Java::Monkstone::ColorUtil.hex_long(c << 16 | c << 8 | c | 0xff000000)
pixels[j * width + i] = col # this is more efficient than set
end
update_pixels
@noise_offset += NS / 2
Expand Down

0 comments on commit 8afe787

Please sign in to comment.