Skip to content

Commit 75155ce

Browse files
committed
Update noise examples
1 parent 68ccd9d commit 75155ce

26 files changed

+480
-102
lines changed

contributed/feather_fractal.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
A = -0.48
2+
B = 0.93
3+
4+
def settings
5+
size(640, 480)
6+
end
7+
8+
def setup
9+
background(235, 215, 182)
10+
color_mode(HSB, 360, 1.0, 1.0)
11+
stroke(0)
12+
sketch_title 'Fantastic Feather Fractal'
13+
no_loop
14+
end
15+
16+
def draw
17+
x = 4.0
18+
y = 0.0
19+
120_000.times do |i|
20+
x1 = B * y + func(x)
21+
y = -x + func(x1)
22+
x = x1
23+
fill(i % 360, 1.0, 1.0)
24+
p = 350 + x * 26
25+
q = 280 - y * 26
26+
circle(p, q, 5)
27+
end
28+
end
29+
30+
def func(x)
31+
A * x - (1.0 - A) * ((2 * (x**2)) / (1.0 + x**2))
32+
end

external_library/gem/ruby_wordcram/render_to_pdf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Liberation Serif font from RedHat: https://www.redhat.com/promo/fonts/
33
require 'ruby_wordcram'
44
load_library :pdf
5-
include_package 'processing.pdf'
5+
66
# After you run this,
77
# open the sketch's folder.
88
# See the PDF.

external_library/java/LiquidFunProcessing/wave_machine.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ def key_released
150150
#######################################
151151

152152
def wave
153-
@m_time += 1 / 120.0
154-
m_joint.set_motor_speed(0.1 * cos(m_time) * PI)
153+
@m_time += 1 / 120.0
154+
# m_joint.set_motor_speed(0.1 * cos(m_time) * PI)
155+
m_joint.set_motor_speed(0.001 * cos(m_time) * PI)
155156
world.update
156157
end
157158

processing_app/basics/math/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pdf
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
3+
Coord = Struct.new(:mx, :my, :mz, :az, :al)
4+
5+
6+
attr_reader :half_w, :half_h, :radius, :spin_x, :spin, :coords
7+
8+
PHI = ((1.0 + Math.sqrt(5)) / 2.0 - 1) * TWO_PI # Fibonacci distribution
9+
10+
def settings
11+
size(480, 480, P3D)
12+
end
13+
14+
def setup
15+
sketch_title '4D Simplex Noise Test'
16+
background(0)
17+
stroke(255)
18+
fill(32, 255, 64)
19+
@half_w = width * 0.5
20+
@half_h = height * 0.5
21+
@radius = height * 0.4
22+
@spin_x = 0.0
23+
@spin = 0.0
24+
@coords = (0..2_000).map do |i|
25+
inc = Math.asin(i / 1_000.0 - 1.0) # inclination
26+
az = PHI * i # azimuth
27+
# Too lazy to do this the right way... precalculating both the angles and the coordinates
28+
Coord.new.tap do |coord|
29+
push_matrix
30+
rotate_y(az)
31+
rotate_z(inc)
32+
translate(radius, 0, 0)
33+
coord.mx = model_x(0, 0, 0) * 0.007
34+
coord.my = model_y(0, 0, 0) * 0.007
35+
coord.mz = model_z(0, 0, 0) * 0.007
36+
coord.az = az
37+
coord.al = inc
38+
pop_matrix
39+
end
40+
end
41+
end
42+
43+
def draw
44+
background(0)
45+
@spin -= (mouse_x - pmouse_x) * 0.0001 if mouse_pressed?
46+
@spin_x += spin
47+
@spin *= 0.98
48+
push_matrix
49+
translate(half_w, half_h, -0)
50+
rotate_y(-spin_x)
51+
coords.each do |ci|
52+
push_matrix
53+
rotate_y(ci.az)
54+
rotate_z(ci.al)
55+
translate(radius, 0, 0)
56+
dst = (modelZ(0, 0, 0) + half_h) / 2 + 32
57+
stroke(dst, dst * 0.5, dst * 0.25)
58+
# 4D Simplex noise(x, y, z, time)
59+
ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI
60+
rotate_x(ang)
61+
line(0, 0, 0, 0, 15, 0)
62+
translate(0, 15, 0)
63+
rotate_x(-10)
64+
line(0, 0, 0, 0, 4, 0)
65+
rotate_x(20)
66+
line(0, 0, 0, 0, 4, 0)
67+
pop_matrix
68+
end
69+
pop_matrix
70+
end

processing_app/basics/math/noise_1_d.rb

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# Noise1D.
2-
#
3-
# Using 1D Perlin Noise to assign location.
1+
# Noise1D.
2+
#
3+
# Using 1D SimplexNoise2 to assign location.
4+
DELTA = 0.01
5+
attr_reader :xoff
46

57
def setup
68
sketch_title 'Noise 1D'
7-
@xoff = 0.0
8-
@x_increment = 0.01
9+
@xoff = 0
910
background 0
10-
no_stroke
11+
no_stroke
1112
end
1213

13-
def draw
14+
def draw
1415
fill 0, 10
15-
rect 0, 0, width, height
16-
n = noise(@xoff) * width
17-
@xoff += @x_increment
16+
rect 0, 0, width, height
17+
n = noise(xoff) * width / 2.0
18+
@xoff += DELTA
1819
fill 200
19-
ellipse n, height / 2, 64, 64
20+
ellipse n, height / 2, 64, 64
2021
end
2122

2223
def settings

processing_app/basics/math/noise_2_d.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
# Noise2D
2-
# by Daniel Shiffman.
3-
#
2+
# after Daniel Shiffman.
3+
# NB: SimplexNoise is in range -1.0 to 1.0
44
# Using 2D noise to create simple texture.
5+
DELTA = 0.01
6+
attr_reader :xoff, :yoff
57

68
def setup
79
sketch_title 'Noise 2D'
8-
@increment = 0.02
910
end
1011

1112
def draw
1213
background 0
1314
load_pixels
14-
xoff = 0.0
15-
detail = map1d(mouse_x, (0..width), (0.1..0.6))
16-
noise_detail(8, detail)
15+
@xoff = 0.0
1716
(0...width).each do |x|
18-
xoff += @increment
19-
yoff = 0.0
17+
@xoff += DELTA
18+
@yoff = 0.0
2019
(0...height).each do |y|
21-
yoff += @increment
22-
bright = noise(xoff, yoff) * 255
20+
@yoff += DELTA
21+
bright = (noise(xoff, yoff) + 1) * 128
2322
pixels[x + y * width] = color(bright)
2423
end
2524
end

processing_app/basics/math/noise_3_d.rb

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
# Noise3D.
2-
#
3-
# Using 3D noise to create simple animated texture.
1+
# Noise3D.
2+
#
3+
# Using 3D noise to create simple animated texture.
44
# Here, the third dimension ('z') is treated as time.
5-
attr_reader :increment, :z_increment
5+
# SimplexNoise is in range -1.0 to 1.0
6+
DELTA = 0.01
7+
DELTA_TIME = 0.02
8+
9+
attr_reader :zoff
610

711
def setup
812
sketch_title 'Noise 3D'
9-
frame_rate 30
10-
@increment = 0.01
13+
frame_rate 30
1114
@zoff = 0.0
12-
@z_increment = 0.02
1315
end
1416

15-
def draw
16-
background 0
17-
load_pixels
18-
xoff = 0.0
19-
(0...width).each do |x|
20-
xoff += increment
21-
yoff = 0.0
22-
(0...height).each do |y|
23-
yoff += increment
24-
bright = noise(xoff, yoff, @zoff) * 255
17+
def draw
18+
background 0
19+
load_pixels
20+
xoff = 0.0
21+
(0...width).each do |x|
22+
xoff += DELTA
23+
yoff = 0.0
24+
(0...height).each do |y|
25+
yoff += DELTA
26+
bright = (noise(xoff, yoff, zoff) + 1) * 128
2527
pixels[x + y * width] = color(bright, bright, bright)
2628
end
27-
end
28-
update_pixels
29-
@zoff += z_increment
29+
end
30+
update_pixels
31+
@zoff += DELTA_TIME
3032
end
3133

3234
def settings
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# OpenSimplex has a range -1.0 to 1.0
3+
4+
SCALE = 0.02
5+
6+
def setup
7+
sketch_title 'Noise Image'
8+
background(0)
9+
stroke(255)
10+
no_fill
11+
end
12+
13+
def draw
14+
background(0)
15+
load_pixels
16+
grid(500, 500) do |x, y|
17+
col = noise(SCALE * x, SCALE * y) > 0 ? 255 : 0
18+
pixels[x + width * y] = color(col, 0, 0)
19+
end
20+
update_pixels
21+
save(data_path('noise_image.png'))
22+
end
23+
24+
def settings
25+
size 500, 500
26+
end

processing_app/basics/math/noise_wave.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
#
22
# Noise Wave
3-
# by Daniel Shiffman.
4-
#
5-
# Using Perlin Noise to generate a wave-like pattern.
3+
# by Daniel Shiffman.
4+
#
5+
# Using Perlin Noise to generate a wave-like pattern.
66
#
77

88
attr_reader :yoff # 2nd dimension of perlin noise
99

1010
def setup
1111
sketch_title 'Noise Wave'
12-
@yoff = 0.0
12+
@yoff = 0.0
1313
end
1414

1515
def draw
1616
background(51)
1717
fill(255)
1818
# We are going to draw a polygon out of the wave points
19-
begin_shape
19+
begin_shape
2020
xoff = 0 # Option #1: 2D Noise
21-
# xoff = yoff # Option #2: 1D Noise
21+
# xoff = yoff # Option #2: 1D Noise
2222
# Iterate over horizontal pixels
2323
(0..width).step(10) do |x|
24-
# Calculate a y value according to noise, map to
25-
y = map1d(noise(xoff, yoff), (0..1.0), (200..300)) # Option #1: 2D Noise
26-
# y = map1d(noise(xoff), (0..1.0), (200..300)) # Option #2: 1D Noise
24+
# Calculate a y value according to noise, map to
25+
y = map1d(noise(xoff, yoff), (-1.0..1.0), (200..300)) # Option #1: 2D Noise
26+
# y = map1d(noise(xoff), (-1.0..1.0), (200..300)) # Option #2: 1D Noise
2727
# Set the vertex
28-
vertex(x, y)
28+
vertex(x, y)
2929
# Increment x dimension for noise
3030
xoff += 0.05
3131
end

processing_app/library/pdf/complex_3D.rb

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# by Marius Watz.
44
#
55
load_library :pdf
6-
include_package 'processing.pdf'
76
attr_reader :num, :pt, :style, :dosave
87

98
def setup

processing_app/library/pdf/large_page.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
# than the screen. When PDF is used as the renderer
77
# (the third parameter of size) the display window
88
# does not open. The file is saved to the sketch folder.
9-
load_libraries 'pdf'
10-
include_package 'processing.pdf'
9+
load_library :pdf
1110

1211
def setup
1312
sketch_title 'Large Page'

processing_app/library/pdf/many_frames.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Multiple Frames.
2-
#
1+
# Multiple Frames.
2+
#
33
# Saves one PDF document of many frames drawn to the screen.
44
# Starts the file when the mouse is pressed and end the file
55
# when the mouse is released.
6-
load_library 'pdf'
7-
include_package 'processing.pdf'
6+
load_library :pdf
87

98
def setup
109
sketch_title 'Many Frames'
@@ -19,7 +18,7 @@ def draw
1918
end
2019

2120
def mouse_pressed
22-
begin_record(PDF, data_path('Lines.pdf'))
21+
begin_record(PDF, data_path('Lines.pdf'))
2322
background(255)
2423
end
2524

processing_app/library/pdf/many_pages.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Saves a new page into a PDF file each loop through draw().
44
# Pressing the mouse finishes writing the file and exits the program.
55
#
6-
load_library 'pdf'
7-
include_package 'processing.pdf'
6+
load_library :pdf
87

98
attr_reader :pdf
109

processing_app/library/pdf/many_pdfs.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Many PDFs.
2-
#
1+
# Many PDFs.
2+
#
33
# Saves one PDF file each each frame while the mouse is pressed.
44
# When the mouse is released, the PDF creation stops.
55
#
6-
load_library 'pdf'
7-
include_package 'processing.pdf'
6+
load_library :pdf
87

98
attr_reader :pdf, :save_pdf
109

@@ -16,7 +15,7 @@ def setup
1615

1716
def draw
1817
begin_record(PDF, data_path("lines#{frame_count}.pdf")) unless !save_pdf
19-
background(255)
18+
background(255)
2019
stroke(0, 20)
2120
stroke_weight(20.0)
2221
line(mouse_x, 0, width-mouse_y, height)

0 commit comments

Comments
 (0)