diff --git a/external_library/gem/toxiclibs/simulation/gray_scott_image.rb b/external_library/gem/toxiclibs/simulation/gray_scott_image.rb index 8a6e4c6..90a2788 100644 --- a/external_library/gem/toxiclibs/simulation/gray_scott_image.rb +++ b/external_library/gem/toxiclibs/simulation/gray_scott_image.rb @@ -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' diff --git a/external_library/gem/toxiclibs/simulation/open_simplex_noise_test.rb b/external_library/gem/toxiclibs/simulation/open_simplex_noise_test.rb new file mode 100644 index 0000000..9013fdb --- /dev/null +++ b/external_library/gem/toxiclibs/simulation/open_simplex_noise_test.rb @@ -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 diff --git a/external_library/gem/toxiclibs/simulation/simplex_noise_test.rb b/external_library/gem/toxiclibs/simulation/simplex_noise_test.rb index 7cbc225..9ce237c 100644 --- a/external_library/gem/toxiclibs/simulation/simplex_noise_test.rb +++ b/external_library/gem/toxiclibs/simulation/simplex_noise_test.rb @@ -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 @@ -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