Skip to content

Commit 0a28d8f

Browse files
committed
Examples demonstrating use of noise_mode.
1 parent 96d631e commit 0a28d8f

22 files changed

+441
-203
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
**3.0** Simplex Noise examples
2+
13
**v1.8** Update examples for hemesh-6.0.1, update pixelflow examples add more gui examples including skatolo

contributed/decagon_grid.rb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
# Example of a grid of decagons with perlin noise after Lenny Herzog
4+
class DecagonGrid < Propane::App
5+
load_library :pdf
6+
NOISE_STRENGTH = 80.0
7+
THETA = 36
8+
attr_reader :version, :save, :noise_generator
9+
10+
def setup
11+
sketch_title 'Decagon Grid'
12+
frame_rate 24
13+
@version = 0
14+
@save = false
15+
@noise_generator = lambda do |x, y, seed|
16+
NOISE_STRENGTH * noise(
17+
x / 150.0,
18+
y / 150.0 + seed * 2,
19+
seed
20+
) - 100
21+
end
22+
end
23+
24+
def draw
25+
begin_record(PDF, data_path("Line_#{version}.pdf")) if save
26+
background(255)
27+
no_fill
28+
stroke(0)
29+
stroke_weight(1)
30+
grid(height + 100, width + 100, 50, 50) do |cy, cx|
31+
begin_shape
32+
(0..360).step(THETA) do |angle|
33+
x = (DegLut.cos(angle) * 60) + cx
34+
y = (DegLut.sin(angle) * 60) + cy
35+
noise_value = noise_generator.call(x, y, millis / 5_000.0)
36+
x += noise_value
37+
y += noise_value
38+
vertex(x, y)
39+
end
40+
end_shape(CLOSE)
41+
end
42+
return unless save
43+
44+
end_record
45+
@version += 1
46+
@save = false
47+
end
48+
49+
def mouse_pressed
50+
@save = true
51+
end
52+
53+
def settings
54+
size(1000, 1000)
55+
end
56+
end
57+
58+
DecagonGrid.new

contributed/terrain.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def eql?(key)
88
key.x == x
99
end
1010
end
11-
# The propane sketch
11+
# The propane sketch press mouse to use SimpleNoise
1212
class Terrain < Propane::App
1313
WIDTH = 1400
1414
HEIGHT = 1100
@@ -43,7 +43,7 @@ def draw
4343
stroke 235, 69, 129
4444
translate width / 2, height / 2
4545
rotate_x PI / 3
46-
translate(-WIDTH / 2, -HEIGHT / 2)
46+
translate(-WIDTH / 2, -HEIGHT / 2)
4747
(0...rows).each do |y|
4848
begin_shape(TRIANGLE_STRIP)
4949
(0..columns).each do |x|
@@ -54,6 +54,18 @@ def draw
5454
end
5555
end
5656

57+
def mouse_pressed
58+
mode = Propane::SIMPLEX
59+
noise_mode mode
60+
sketch_title "#{mode}"
61+
end
62+
63+
def mouse_released
64+
mode = Propane::VALUE
65+
noise_mode(mode)
66+
sketch_title "#{mode}"
67+
end
68+
5769
private
5870

5971
def renderer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env jruby -w
2+
require 'propane'
3+
require 'toxiclibs'
4+
java_import 'toxi.geom.Circle'
5+
6+
class CircleResolution < Propane::App
7+
attr_reader :gfx
8+
def setup
9+
sketch_title 'Circle Resolution'
10+
@gfx = Gfx::ToxiclibsSupport.new(self)
11+
end
12+
13+
def draw
14+
background(0)
15+
no_stroke
16+
fill(255)
17+
res = map1d(mouse_x, 0..width, 3..72)
18+
poly = Circle.new(TVec2D.new(width / 2, height / 2), 200).toPolygon2D(res)
19+
gfx.polygon2D(poly)
20+
fill(255, 0, 0)
21+
poly.each { |vertex| gfx.circle(vertex, 5) }
22+
text(res, 20, 20)
23+
end
24+
25+
def settings
26+
size(600, 600)
27+
smooth 8
28+
end
29+
end
30+
31+
CircleResolution.new

external_library/gem/toxiclibs/geometry/voronoi1.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def draw
2121
smooth
2222
stroke_weight 1
2323
stroke 255
24-
voronoi.get_regions.each { |polygon| gfx.polygon2D(polygon) }
24+
voronoi.get_regions.each { |polygon| gfx.polygon2D(polygon) }
2525
save_frame(data_path('voronoi-001.png'))
2626
end
2727

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'propane'
2+
3+
class DemoNoise < Propane::App
4+
attr_reader :z
5+
6+
def setup
7+
sketch_title 'Demo noise_mode'
8+
stroke(255, 64)
9+
@z = 0
10+
end
11+
12+
def draw
13+
noise_scale = 0.01
14+
background(0)
15+
grid(width, height, 10, 10) do |x, y|
16+
arrow(x, y, noise(x * noise_scale, y * noise_scale, z * noise_scale) * TWO_PI * 2)
17+
end
18+
@z += 1
19+
end
20+
21+
def mouse_pressed
22+
mode = Propane::SIMPLEX
23+
noise_mode mode
24+
sketch_title "#{mode}"
25+
end
26+
27+
def mouse_released
28+
mode = Propane::VALUE
29+
noise_mode(mode)
30+
sketch_title "#{mode}"
31+
end
32+
33+
34+
def arrow(x, y, ang)
35+
pushMatrix()
36+
translate(x, y)
37+
rotate(ang)
38+
line(0, 0, 20, 0)
39+
translate(20, 0)
40+
rotate(PI + 0.4)
41+
line(0, 0, 5, 0)
42+
rotate(-0.8)
43+
line(0, 0, 5, 0)
44+
popMatrix()
45+
end
46+
47+
def settings
48+
size(600, 400, P2D)
49+
end
50+
end
51+
52+
DemoNoise.new
+37-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
# Noise1D.
2-
#
3-
# Using 1D Perlin Noise to assign location.
1+
#!/usr/bin/env jruby -v -W2
2+
# frozen_string_literal: true
3+
require 'propane'
44

5-
def setup
6-
sketch_title 'Noise 1D'
7-
@xoff = 0.0
8-
@x_increment = 0.01
9-
background 0
10-
no_stroke
11-
end
5+
class Noise1D < Propane::App
126

13-
def draw
14-
fill 0, 10
15-
rect 0, 0, width, height
16-
n = noise(@xoff) * width
17-
@xoff += @x_increment
18-
fill 200
19-
ellipse n, height / 2, 64, 64
20-
end
7+
def setup
8+
sketch_title 'Noise 1D'
9+
@xoff = width / 2
10+
@x_increment = 0.01
11+
background 0
12+
no_stroke
13+
end
14+
15+
def draw
16+
fill 0, 10
17+
rect 0, 0, width, height
18+
n = noise(@xoff) * width
19+
@xoff += @x_increment
20+
fill 200
21+
ellipse n, height / 2, 64, 64
22+
end
2123

22-
def settings
23-
size 640, 360
24+
def mouse_pressed
25+
mode = Propane::SIMPLEX
26+
noise_mode mode
27+
sketch_title "#{mode}"
28+
end
29+
30+
def mouse_released
31+
mode = Propane::VALUE
32+
noise_mode(mode)
33+
sketch_title "#{mode}"
34+
end
35+
36+
def settings
37+
size 640, 360
38+
end
2439
end
40+
41+
Noise1D.new

processing_app/basics/math/noise_3_d.rb

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
#!/usr/bin/env jruby -v -W2
22
# frozen_string_literal: true
33
require 'propane'
4-
# Noise3D.
5-
#
6-
# Using 3D noise to create simple animated texture.
4+
# Noise3D.
5+
#
6+
# Using 3D noise to create simple animated texture.
77
# Here, the third dimension ('z') is treated as time.
8+
# Press mouse to switch Noise Implementions.
89
class Noise3D < Propane::App
910
attr_reader :increment, :z_increment
10-
11+
1112
def setup
1213
sketch_title 'Noise 3D'
13-
frame_rate 30
14+
frame_rate 30
1415
@increment = 0.01
1516
@zoff = 0.0
16-
@z_increment = 0.02
17+
@z_increment = 0.02
1718
end
18-
19-
def draw
20-
background 0
21-
load_pixels
22-
xoff = 0.0
23-
(0...width).each do |x|
19+
20+
def draw
21+
background 0
22+
load_pixels
23+
xoff = 0.0
24+
(0...width).each do |x|
2425
xoff += increment
25-
yoff = 0.0
26-
(0...height).each do |y|
27-
yoff += increment
28-
bright = noise(xoff, yoff, @zoff) * 255
26+
yoff = 0.0
27+
(0...height).each do |y|
28+
yoff += increment
29+
bright = noise(xoff, yoff, @zoff) * 255
2930
pixels[x + y * width] = color(bright, bright, bright)
3031
end
31-
end
32-
update_pixels
33-
@zoff += z_increment
32+
end
33+
update_pixels
34+
@zoff += z_increment
35+
end
36+
37+
def mouse_pressed
38+
mode = Propane::SIMPLEX
39+
noise_mode mode
40+
sketch_title "#{mode}"
3441
end
35-
42+
43+
def mouse_released
44+
mode = Propane::VALUE
45+
noise_mode(mode)
46+
sketch_title "#{mode}"
47+
end
48+
3649
def settings
3750
size 640, 360
3851
end

processing_app/library/simplex_noise/simplex_noise_texture.rb renamed to processing_app/basics/math/noise_texture.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'propane'
44

55
class Noise < Propane::App
6-
load_library :simplex_noise
76

87
# by Martin Prout.
98
# Using noise to create simple texture.
@@ -24,13 +23,25 @@ def draw
2423
yoff = 0.0
2524
(0...height).each do |y|
2625
yoff += @increment
27-
bright = SimplexNoise.noise(x / x_val, y / x_val) * 255
26+
bright = noise(x / x_val, y / x_val) * 255
2827
pixels[x + y * width] = color(bright)
2928
end
3029
end
3130
update_pixels
3231
end
3332

33+
def mouse_pressed
34+
mode = Propane::SIMPLEX
35+
noise_mode mode
36+
sketch_title "#{mode}"
37+
end
38+
39+
def mouse_released
40+
mode = Propane::VALUE
41+
noise_mode(mode)
42+
sketch_title "#{mode}"
43+
end
44+
3445
def settings
3546
size 640, 360
3647
end

0 commit comments

Comments
 (0)