Skip to content

Commit 16dbb67

Browse files
committed
more noise examples
1 parent 6fc407e commit 16dbb67

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

contributed/etienne.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
# After a sSketch by Etienne Jacob
5+
class Etienne < Propane::App
6+
NUM_FRAMES = 38
7+
8+
def setup
9+
sketch_title 'Etienne Sketch'
10+
end
11+
12+
def periodic_function(p, seed, x, y)
13+
radius = 1.3
14+
scl = 0.018
15+
1.0 * noise(seed + radius * cos(TWO_PI * p), radius * sin(TWO_PI * p), scl * x, scl * y)
16+
end
17+
18+
def offset(x, y)
19+
0.015 * dist(x, y, width / 2, height / 2)
20+
end
21+
22+
def draw
23+
background(0)
24+
t = 1.0 * frameCount / NUM_FRAMES
25+
m = 450
26+
stroke(255, 50)
27+
stroke_weight(1.5)
28+
grid(m, m) do |i, j|
29+
margin = 50
30+
x = map1d(i, 0..m - 1, margin..width - margin)
31+
y = map1d(j, 0..m - 1, margin..height - margin)
32+
dx = 20.0 * periodic_function(t - offset(x, y), 0, x, y)
33+
dy = 20.0 * periodic_function(t - offset(x, y), 123, x, y)
34+
point(x + dx, y + dy)
35+
end
36+
save_frame('fr###.gif') if frameCount <= NUM_FRAMES
37+
return unless frame_count == NUM_FRAMES
38+
39+
puts('All frames have been saved')
40+
stop
41+
end
42+
43+
def settings
44+
size 500, 500
45+
end
46+
end
47+
48+
Etienne.new
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# Noise Generator
4+
class Generator
5+
include SmoothNoise
6+
attr_reader :nx, :ny, :nz, :remap1, :remap2
7+
8+
R = 6
9+
RR = 1
10+
11+
def initialize(phi, theta)
12+
base = R + RR * Math.cos(phi)
13+
tx = base * Math.cos(theta)
14+
ty = base * Math.sin(theta)
15+
tz = RR * Math.sin(phi)
16+
@nx = MathTool.norm(tx, 0.0, R + RR)
17+
@ny = MathTool.norm(ty, 0.0, R + RR)
18+
@nz = MathTool.norm(tz, 0.0, RR)
19+
@remap1 = ->(a, b, c) { ((SmoothNoise.noise(a, b, c) + 1) * 128).floor }
20+
@remap2 = ->(a, b) { ((SmoothNoise.noise(a, b) + 1) * 128).floor }
21+
end
22+
23+
def noisef(time)
24+
remap2.call(remap1.call(nx, ny, nz), time)
25+
end
26+
end

contributed/psychedelic_noise.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
# Based on a sketch by Javi F Gorostiza
5+
# https://openprocessing.org/sketch/432548
6+
class PsychedelicNoise < Propane::App
7+
load_library :generator
8+
attr_reader :img, :colors, :remap1, :remap2
9+
10+
def setup
11+
sketch_title 'Psychedelic Noise Pattern'
12+
color_mode(RGB, 1.0)
13+
@theta = 0
14+
@phi = 0
15+
# the dimensions of the image are twice the dimentions of
16+
# the canvas to add antialiasing when the image is reduced
17+
@img = create_image(2 * width, 2 * height, RGB)
18+
@colors = (0..255).map { color(rand, rand, rand) }
19+
end
20+
21+
22+
def draw
23+
# fill the array with rand colors
24+
# create pattern
25+
img.load_pixels
26+
iwidth = img.width
27+
iheight = img.height
28+
29+
grid(iwidth, iheight) do |x, y|
30+
# map x and y to angles between 0 and TWO_PI
31+
theta = map1d(x, 0..iwidth, 0..TWO_PI)
32+
phi = map1d(y, 0..iheight, 0..TWO_PI)
33+
generator = Generator.new(phi, theta)
34+
# apply noise twice and use the equivalent color on the pallete
35+
img.pixels[x + y * iwidth] = colors[generator.noisef(frame_count / 5)]
36+
end
37+
img.update_pixels
38+
# display pattern
39+
image(img, 0, 0, width, height) # the image is reduce to the size of the canvas to make it smooth
40+
end
41+
42+
def key_pressed
43+
save(data_path('image.png'))
44+
end
45+
46+
def settings
47+
size(500, 500)
48+
end
49+
end
50+
51+
PsychedelicNoise.new

0 commit comments

Comments
 (0)