diff --git a/basics/math/data/noise_image.png b/basics/math/data/noise_image.png new file mode 100644 index 0000000..83ce0b1 Binary files /dev/null and b/basics/math/data/noise_image.png differ diff --git a/basics/math/noise4_tap.rb b/basics/math/noise4_tap.rb index cf8ca3d..6e2a998 100644 --- a/basics/math/noise4_tap.rb +++ b/basics/math/noise4_tap.rb @@ -4,7 +4,7 @@ Coord = Struct.new(:mx, :my, :mz, :az, :al) class ForD < Processing::App - attr_reader :half_w, :half_h, :radius, :spin_x, :spin, :coords + attr_reader :half_w, :half_h, :radius, :spin_x, :spin, :coords, :smth def settings size(480, 480, P3D) @@ -20,7 +20,7 @@ def setup @radius = height * 0.4 @spin_x = 0.0 @spin = 0.0 - + @smth = false angle = ((1.0 + Math.sqrt(5)) / 2.0 - 1) * TWO_PI # Fibonacci distribution @coords = (0..2_000).map do |i| inc = Math.asin(i / 1_000.0 - 1.0) # inclination @@ -31,9 +31,9 @@ def setup rotate_y(az) rotate_z(inc) translate(radius, 0, 0) - coord.mx = model_x(0, 0, 0) * 0.007 - coord.my = model_y(0, 0, 0) * 0.007 - coord.mz = modelZ(0, 0, 0) * 0.007 + coord.mx = g.model_x(0, 0, 0) * 0.007 + coord.my = g.model_y(0, 0, 0) * 0.007 + coord.mz = g.model_z(0, 0, 0) * 0.007 coord.az = az coord.al = inc pop_matrix @@ -54,10 +54,14 @@ def draw rotate_y(ci.az) rotate_z(ci.al) translate(radius, 0, 0) - dst = (modelZ(0, 0, 0) + half_h) / 2 + 32 + dst = (g.model_z(0, 0, 0) + half_h) / 2 + 32 stroke(dst, dst * 0.5, dst * 0.25) # 4D Simplex noise(x, y, z, time) - ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI + if smth + ang = SmoothNoise.noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI + else + ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI + end rotate_x(ang) line(0, 0, 0, 0, 15, 0) translate(0, 15, 0) @@ -71,15 +75,7 @@ def draw end def mouse_pressed - mode = NoiseMode::OPEN_SMOOTH - sketch_title mode.description - noise_mode mode - end - - def mouse_released - mode = NoiseMode::DEFAULT - sketch_title mode.description - noise_mode mode + @smth = !smth end end diff --git a/basics/math/noise_1_d.rb b/basics/math/noise_1_d.rb index 829dbfd..87cf286 100644 --- a/basics/math/noise_1_d.rb +++ b/basics/math/noise_1_d.rb @@ -2,6 +2,7 @@ require 'picrate' class Noise1D < Processing::App + attr_reader :smth def setup sketch_title 'Noise 1D' @@ -9,27 +10,20 @@ def setup @x_increment = 0.01 background 0 no_stroke + @smth = false end def draw fill 0, 10 rect 0, 0, width, height - n = noise(@xoff) * width + n = smth ? SmoothNoise.noise(@xoff) * width : noise(@xoff) * width @xoff += @x_increment fill 200 ellipse n, height / 2, 64, 64 end def mouse_pressed - mode = NoiseMode::OPEN_SMOOTH - sketch_title mode.description - noise_mode mode - end - - def mouse_released - mode = NoiseMode::DEFAULT - sketch_title mode.description - noise_mode mode + @smth = !smth end def settings diff --git a/basics/math/noise_2_d.rb b/basics/math/noise_2_d.rb index 8f401c1..69823b0 100644 --- a/basics/math/noise_2_d.rb +++ b/basics/math/noise_2_d.rb @@ -1,43 +1,35 @@ # frozen_string_literal: true require 'picrate' +# Noise2D +# by Daniel Shiffman. +# +# Using 2D noise to create simple texture. class Noise2D < Processing::App - # Noise2D - # by Daniel Shiffman. - # - # Using 2D noise to create simple texture. + attr_reader :smth def setup sketch_title 'Noise 2D' - @increment = 0.02 + @inc = 0.02 + @smth = false end def draw background 0 load_pixels - xoff = 0.0 - (0...width).each do |x| - xoff += @increment - yoff = 0.0 - (0...height).each do |y| - yoff += @increment - bright = noise(xoff, yoff) * 255 - pixels[x + y * width] = color(bright) + grid(width, height) do |x, y| + if smth + bright = (SmoothNoise.noise(x * @inc, y * @inc) + 1) * 128 + else + bright = (noise(x * @inc, y * @inc) + 1) * 128 end + pixels[x + y * width] = color(bright) end update_pixels end def mouse_pressed - mode = NoiseMode::OPEN_SMOOTH - sketch_title mode.description - noise_mode mode - end - - def mouse_released - mode = NoiseMode::DEFAULT - sketch_title mode.description - noise_mode mode + @smth = !smth end def settings diff --git a/basics/math/noise_3_d.rb b/basics/math/noise_3_d.rb index fa781dc..a23c4a8 100644 --- a/basics/math/noise_3_d.rb +++ b/basics/math/noise_3_d.rb @@ -5,12 +5,12 @@ # Using 3D noise to create simple animated texture. # Here, the third dimension ('z') is treated as time. class Noise3D < Processing::App - attr_reader :increment, :z_increment + attr_reader :bright, :inc, :z_increment, :smth def setup sketch_title 'Noise 3D' frame_rate 30 - @increment = 0.01 + @inc = 0.01 @zoff = 0.0 @z_increment = 0.02 end @@ -18,30 +18,20 @@ def setup def draw background 0 load_pixels - xoff = 0.0 - (0...width).each do |x| - xoff += increment - yoff = 0.0 - (0...height).each do |y| - yoff += increment - bright = noise(xoff, yoff, @zoff) * 255 - pixels[x + y * width] = color(bright, bright, bright) + grid(width, height) do |x, y| + if smth + @bright = (SmoothNoise.noise(x * inc, y * inc, @zoff) + 1) * 128 + else + @bright = (noise(x * inc, y * inc, @zoff) + 1) * 128 end + pixels[x + y * width] = color(bright, bright, bright) end update_pixels @zoff += z_increment end def mouse_pressed - mode = NoiseMode::OPEN_SMOOTH - sketch_title mode.description - noise_mode mode - end - - def mouse_released - mode = NoiseMode::DEFAULT - sketch_title mode.description - noise_mode mode + @smth = !smth end def settings diff --git a/basics/math/noise_animation.rb b/basics/math/noise_animation.rb index b1ec59d..f5fd66b 100644 --- a/basics/math/noise_animation.rb +++ b/basics/math/noise_animation.rb @@ -45,11 +45,9 @@ def draw point(pos.x, pos.y) end # puts frame_count - save_frame(data_path('fr###.tiff')) - + # save_frame(data_path('fr###.tiff')) return unless frame_count == FRAMES - # save_frame(data_path('expt6.png')) no_loop puts 'finished' end diff --git a/basics/math/noise_image.rb b/basics/math/noise_image.rb index edca33b..fdddaa5 100644 --- a/basics/math/noise_image.rb +++ b/basics/math/noise_image.rb @@ -1,6 +1,7 @@ require 'picrate' # OpenSimplex2 has a range -1.0 to 1.0 class NoiseImage < Processing::App + attr_reader :col, :smth SCALE = 0.02 def setup @@ -8,6 +9,7 @@ def setup background(0) stroke(255) no_fill + @smth = false end def draw @@ -15,7 +17,11 @@ def draw scale = 0.02 load_pixels grid(500, 500) do |x, y| - col = noise(SCALE * x, SCALE * y) > 0 ? 255 : 0 + if smth + @col = SmoothNoise.noise(SCALE * x, SCALE * y) > 0 ? 255 : 0 + else + @col = noise(SCALE * x, SCALE * y) > 0 ? 255 : 0 + end pixels[x + width * y] = color(col, 0, 0) end update_pixels @@ -25,6 +31,10 @@ def draw def settings size 500, 500 end + + def mouse_pressed + @smth = !smth + end end NoiseImage.new diff --git a/basics/math/noise_wave.rb b/basics/math/noise_wave.rb index 82759b7..2b358b8 100644 --- a/basics/math/noise_wave.rb +++ b/basics/math/noise_wave.rb @@ -3,14 +3,16 @@ # Noise Wave # by Daniel Shiffman. # -# Using Perlin Noise to generate a wave-like pattern. +# Using Simplex Noise to generate a wave-like pattern. class NoiseWave < Processing::App - attr_reader :yoff # 2nd dimension of perlin noise + attr_reader :y, :yoff, :inc, :smth # 2nd dimension of perlin noise def setup sketch_title 'Noise Wave' @yoff = 0.0 + @smth = false + @inc = 0.005 end def draw @@ -18,17 +20,19 @@ def draw fill(255) # We are going to draw a polygon out of the wave points begin_shape - xoff = 0 # Option #1: 2D Noise # xoff = yoff # Option #2: 1D Noise # Iterate over horizontal pixels (0..width).step(10) do |x| # Calculate a y value according to noise, map to - y = map1d(noise(xoff, yoff), (0..1.0), (200..300)) # Option #1: 2D Noise - # y = map1d(noise(xoff), (0..1.0), (200..300)) # Option #2: 1D Noise + if smth + @y = map1d(SmoothNoise.noise(x * inc, yoff), (-1.0..1.0), (200..300)) # Option #1: 2D Noise + else + @y = map1d(noise(x * inc, yoff), (-1.0..1.0), (200..300)) # Option #1: 2D Noise + end + # y = map1d(noise(xoff), (-1.0..1.0), (200..300)) # Option #2: 1D Noise # Set the vertex vertex(x, y) # Increment x dimension for noise - xoff += 0.05 end # increment y dimension for noise @yoff += 0.01 @@ -37,17 +41,8 @@ def draw end_shape(CLOSE) end - def mouse_pressed - mode = NoiseMode::OPEN_SMOOTH - sketch_title mode.description - noise_mode mode - end - - def mouse_released - mode = NoiseMode::DEFAULT - sketch_title mode.description - noise_mode mode + @smth = !smth end def settings diff --git a/contributed/decagon_grid.rb b/contributed/decagon_grid.rb index b9b35ad..29b7bda 100644 --- a/contributed/decagon_grid.rb +++ b/contributed/decagon_grid.rb @@ -1,11 +1,11 @@ #!/usr/bin/env jruby - require 'picrate' # Example of a grid of decagons with perlin noise after Lenny Herzog class DecagonGrid < Processing::App + load_library :pdf NOISE_STRENGTH = 80.0 THETA = 36 - attr_reader :version, :noise_generator + attr_reader :version, :save, :noise_generator def setup sketch_title 'Decagon Grid' @@ -13,7 +13,7 @@ def setup @version = 0 @save = false @noise_generator = lambda do |x, y, seed| - NOISE_STRENGTH * noise( + NOISE_STRENGTH * SmoothNoise.tnoise( x / 150.0, y / 150.0 + seed * 2, seed @@ -22,6 +22,7 @@ def setup end def draw + begin_record(PDF, data_path("Line_#{version}.pdf")) if save background(255) no_fill stroke(0) @@ -38,14 +39,15 @@ def draw end end_shape(CLOSE) end - end + return unless save - def mouse_pressed - noise_mode NoiseMode::OPEN_SMOOTH + end_record + @version += 1 + @save = false end def mouse_pressed - noise_mode NoiseMode::DEFAULT + @save = true end def settings diff --git a/contributed/etienne.rb b/contributed/etienne.rb new file mode 100755 index 0000000..a71b57c --- /dev/null +++ b/contributed/etienne.rb @@ -0,0 +1,48 @@ +#!/usr/bin/env jruby +require 'picrate' + +# After a sSketch by Etienne Jacob +class Etienne < Processing::App + NUM_FRAMES = 38 + + def setup + sketch_title 'Etienne Sketch' + end + + def periodic_function(p, seed, x, y) + radius = 1.3 + scl = 0.018 + 1.0 * noise(seed + radius * cos(TWO_PI * p), radius * sin(TWO_PI * p), scl * x, scl * y) + end + + def offset(x, y) + 0.015 * dist(x, y, width / 2, height / 2) + end + + def draw + background(0) + t = 1.0 * frameCount / NUM_FRAMES + m = 450 + stroke(255, 50) + stroke_weight(1.5) + grid(m, m) do |i, j| + margin = 50 + x = map1d(i, 0..m - 1, margin..width - margin) + y = map1d(j, 0..m - 1, margin..height - margin) + dx = 20.0 * periodic_function(t - offset(x, y), 0, x, y) + dy = 20.0 * periodic_function(t - offset(x, y), 123, x, y) + point(x + dx, y + dy) + end + # save_frame('fr###.gif') if frameCount <= NUM_FRAMES + return unless frame_count == NUM_FRAMES + + # puts('All frames have been saved') + stop + end + + def settings + size 500, 500 + end +end + +Etienne.new diff --git a/data/henon_2.0000.jpg.tif b/data/henon_2.0000.jpg.tif deleted file mode 100644 index 90c1a70..0000000 Binary files a/data/henon_2.0000.jpg.tif and /dev/null differ diff --git a/data/wovns.png b/data/wovns.png deleted file mode 100644 index 88fced4..0000000 Binary files a/data/wovns.png and /dev/null differ diff --git a/demo/terreno.rb b/demo/terreno.rb index a3a7ab8..6ae86e4 100644 --- a/demo/terreno.rb +++ b/demo/terreno.rb @@ -1,3 +1,4 @@ +#!/usr/bin/env jruby require 'picrate' #Terreno @@ -27,7 +28,7 @@ def draw for y in 0..@filas xoff = 0 for x in 0..@col - @terreno["#{x}.#{y}"]= p5map noise(xoff,yoff), 0, 1, -65, 65 + @terreno["#{x}.#{y}"]= map1d tnoise(xoff,yoff), -1.0..1.0, -65..65 xoff += 0.2 end yoff += 0.2 @@ -47,14 +48,6 @@ def draw end_shape(CLOSE) end end - - def mouse_pressed - noise_mode NoiseMode::FAST_TERRAIN - end - - def mouse_released - noise_mode NoiseMode::SMOOTH_TERRAIN - end end Terreno.new diff --git a/external_library/gems/geomerative/library/f_agent/f_agent.rb b/external_library/gems/geomerative/library/f_agent/f_agent.rb index 70fed58..df4431c 100644 --- a/external_library/gems/geomerative/library/f_agent/f_agent.rb +++ b/external_library/gems/geomerative/library/f_agent/f_agent.rb @@ -12,18 +12,20 @@ def initialize(loc:, increment:) def motion @offset += increment - loc.dist(Vec2D.new(noise(offset.x) * width, noise(offset.y) * height)) + hw = width / 2 + hh = height / 2 + loc.dist(Vec2D.new((noise(offset.x) + 1) * hw, (noise(offset.y) + 1) * hh)) end def display(xr:, yr:, m_point:) no_stroke - fill(255, 73) - dia = (150 / m_point) * 5 + fill(255, 100) + dia = (150 / m_point) * 7 # to get weird non-deterministic behaviour of original, created by use of # negative inputs to a random range surely not intended, use original:- # ellipse(loc.x + random(-xr, xr), loc.y + random(-yr, yr), dia, dia) - xr *= -1 if xr < 0 # guards against an invalid hi..low range - yr *= -1 if yr < 0 + xr *= -1 if xr.negative? # guards against an invalid hi..low range + yr *= -1 if yr.negative? ellipse(loc.x + rand(-xr..xr), loc.y + rand(-yr..yr), dia, dia) end end diff --git a/external_library/gems/geomerative/library/font_agent/font_agent.rb b/external_library/gems/geomerative/library/font_agent/font_agent.rb index 1267270..1890260 100644 --- a/external_library/gems/geomerative/library/font_agent/font_agent.rb +++ b/external_library/gems/geomerative/library/font_agent/font_agent.rb @@ -11,9 +11,9 @@ def initialize(location:) def motion noise_scale = map1d(mouse_x, (0..width), (0.001..0.01)) - noise_z = map1d(mouse_x, (0..height), (frame_count * 0.0003..frame_count * 0.02)) + noise_z = map1d(mouse_y, (0..height), (frame_count * 0.0003..frame_count * 0.02)) noise_vector = loc * noise_scale * noise_z - @mot = noise(noise_vector.x, noise_vector.y) * 53 + @mot = (noise(noise_vector.x, noise_vector.y) + 1) * 26.5 end def display(step:) diff --git a/external_library/gems/geomerative/picrate_merge.rb b/external_library/gems/geomerative/picrate_merge.rb index 94f983a..5518742 100644 --- a/external_library/gems/geomerative/picrate_merge.rb +++ b/external_library/gems/geomerative/picrate_merge.rb @@ -52,8 +52,8 @@ def setup def draw background(0, 50) - displace_x = noise(xoff) * width - displace_y = noise(yoff) * height + displace_x = (noise(xoff) + 1) * width / 2 + displace_y = (noise(yoff) + 1) * height / 2 @xoff += x_inc @yoff += y_inc translate(width / 2, height / 1.7) diff --git a/external_library/gems/geomerative/typo_extra_bright.rb b/external_library/gems/geomerative/typo_extra_bright.rb index b961922..4abd92e 100644 --- a/external_library/gems/geomerative/typo_extra_bright.rb +++ b/external_library/gems/geomerative/typo_extra_bright.rb @@ -1,3 +1,4 @@ +#!/usr/bin/env jruby require 'picrate' require 'geomerative' diff --git a/external_library/gems/geomerative/typo_merge.rb b/external_library/gems/geomerative/typo_merge.rb index d275c6c..b0c219f 100644 --- a/external_library/gems/geomerative/typo_merge.rb +++ b/external_library/gems/geomerative/typo_merge.rb @@ -23,7 +23,6 @@ # http://www.ricardmarxer.com/geomerative/ # # More info on these tutorials and workshops at : -# www.freeartbureau.org/blog # # Adapted for picrate by Martin Prout ####################### @@ -52,8 +51,8 @@ def setup def draw background(0, 50) - displace_x = noise(xoff) * width - displace_y = noise(yoff) * height + displace_x = (noise(xoff) + 1) * width / 2 + displace_y = (noise(yoff) + 1) * height / 2 @xoff += x_inc @yoff += y_inc translate(width / 2, height / 1.7) diff --git a/external_library/gems/pbox2d/lib/surface.rb b/external_library/gems/pbox2d/lib/surface.rb index 96bcb0f..6e3146a 100644 --- a/external_library/gems/pbox2d/lib/surface.rb +++ b/external_library/gems/pbox2d/lib/surface.rb @@ -24,9 +24,9 @@ def initialize(app) # Doing some stuff with perlin noise to calculate a surface that points # down on one side and up on the other if x > width / 2 - @y = 100 + (width - x) * 1.1 + map1d(noise(xoff), (0..1.0), (-80..80)) + @y = 100 + (width - x) * 1.1 + map1d(SmoothNoise.noise(xoff), (-1.0..1.0), (-80..80)) else - @y = 100 + x * 1.1 + map1d(noise(xoff), (0..1.0), (-80..80)) + @y = 100 + x * 1.1 + map1d(SmoothNoise.noise(xoff), (-1.0..1.0), (-80..80)) end # Store the vertex in screen coordinates surface << Vec2.new(x, y) diff --git a/library/vecmath/vec3d/terrain.rb b/library/vecmath/vec3d/terrain.rb index 93465a6..7f79f54 100644 --- a/library/vecmath/vec3d/terrain.rb +++ b/library/vecmath/vec3d/terrain.rb @@ -1,20 +1,31 @@ +#!/usr/bin/env jruby require 'picrate' +# Alternative to using array or string as key +Key = Struct.new(:x, :y) do + def eql?(key) + return false unless key.y == y + key.x == x + end +end +# The propane sketch press mouse to use SimpleNoise class Terrain < Processing::App - WIDTH = 1_400 - HEIGHT = 1_100 + WIDTH = 1400 + HEIGHT = 1100 SCL = 30 - attr_reader :terrain, :rows, :columns, :mover + attr_reader :terrain, :rows, :columns, :mover, :smth def settings size 800, 800, P3D end def setup + sketch_title 'Terrain' @columns = WIDTH / SCL @rows = HEIGHT / SCL @terrain = {} @mover = 0 + @smth = false end def draw @@ -24,7 +35,11 @@ def draw (0..rows).each do |y| xoff = 0 (0..columns).each do |x| - terrain[hash_key(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(noise(xoff, yoff), 0..1.0, -65..65)) + if smth + terrain[Key.new(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(SmoothNoise.tnoise(xoff, yoff), -1.0..1.0, -65..65)) + else + terrain[Key.new(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(tnoise(xoff, yoff), -1.0..1.0, -65..65)) + end xoff += 0.2 end yoff += 0.2 @@ -37,20 +52,19 @@ def draw (0...rows).each do |y| begin_shape(TRIANGLE_STRIP) (0..columns).each do |x| - terrain[hash_key(x, y)].to_vertex(renderer) - terrain[hash_key(x, y.succ)].to_vertex(renderer) + terrain[Key.new(x, y)].to_vertex(renderer) + terrain[Key.new(x, y.succ)].to_vertex(renderer) end end_shape end end - private - - # HACK should be safe here - def hash_key(x, y) - WIDTH * y + x + def mouse_pressed + @smth = !smth end + private + def renderer @renderer ||= GfxRender.new(self.g) end diff --git a/library/vector_utils/fibonacci.rb b/library/vector_utils/fibonacci.rb index afcf348..6b07bcc 100644 --- a/library/vector_utils/fibonacci.rb +++ b/library/vector_utils/fibonacci.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +#!/usr/bin/env jruby require 'picrate' require 'arcball'