Skip to content

Commit 5fc8d84

Browse files
committed
Update noise examples
1 parent dffed4c commit 5fc8d84

File tree

20 files changed

+229
-145
lines changed

20 files changed

+229
-145
lines changed

contributed/decagon_grid.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Example of a grid of decagons with perlin noise after Lenny Herzog
22

3-
load_library :pdf
4-
NOISE_STRENGTH = 80.0
3+
# load_library :pdf
4+
NOISE_STRENGTH = 40.0
55
THETA = 36
66
attr_reader :version, :save, :noise_generator
77

@@ -11,12 +11,12 @@ def setup
1111
@version = 0
1212
@save = false
1313
@noise_generator = lambda do |x, y, seed|
14-
NOISE_STRENGTH * noise(
14+
NOISE_STRENGTH * SmoothNoise.tnoise(
1515
x / 150.0,
1616
y / 150.0 + seed * 2,
1717
seed
18-
) - 100
19-
end
18+
) - 100
19+
end
2020
end
2121

2222
def draw

contributed/etienne.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# After a sketch by Etienne Jacob @etiennejcb
2+
3+
NUM_FRAMES = 38
4+
5+
def setup
6+
sketch_title 'Etienne Sketch'
7+
end
8+
9+
def periodic_function(p, seed, x, y)
10+
radius = 1.3
11+
scl = 0.018
12+
1.0 * noise(seed + radius * cos(TWO_PI * p), radius * sin(TWO_PI * p), scl * x, scl * y)
13+
end
14+
15+
def offset(x, y)
16+
0.015 * dist(x, y, width / 2, height / 2)
17+
end
18+
19+
def draw
20+
background(0)
21+
t = 1.0 * frame_count / NUM_FRAMES
22+
m = 450
23+
stroke(255, 50)
24+
stroke_weight(1.5)
25+
grid(m, m) do |i, j|
26+
margin = 50
27+
x = map1d(i, 0..m - 1, margin..width - margin)
28+
y = map1d(j, 0..m - 1, margin..height - margin)
29+
dx = 20.0 * periodic_function(t - offset(x, y), 0, x, y)
30+
dy = 20.0 * periodic_function(t - offset(x, y), 123, x, y)
31+
point(x + dx, y + dy)
32+
end
33+
save_frame(data_path('fr###.png')) if frame_count <= NUM_FRAMES
34+
return unless frame_count == NUM_FRAMES
35+
36+
puts('All frames have been saved')
37+
stop
38+
end
39+
40+
def settings
41+
size 500, 500
42+
end

contributed/noise_add.rb

-32
This file was deleted.

contributed/spiky_orb.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# After a vanilla processing sketch by
33
# Ben Notorianni aka lazydog
44
# Features dynamic creation of a colour table
5+
# Use 's' key to toggle spikes
56
BALL_RADIUS = 160
67

78
attr_reader :colour_table, :orb_vertices, :flat, :smoothing, :sub_division_depth
@@ -140,7 +141,7 @@ def generate_radii(base_radius, depth)
140141
return (0..depth).map { base_radius } if flat
141142

142143
(0..depth).map do |i|
143-
r = 2 * noise(frame_count * 0.003, (i.to_f / depth) - 1.0)
144+
r = noise(frame_count * 0.003, (i.to_f / depth) - 1) + 1
144145
base_radius * (0.9 * r)
145146
end
146147
end

contributed/terreno.rb

+58-48
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,58 @@
1-
#Terreno
2-
#
3-
# Transcrito a Jruby_Art por Carlos Rocha
4-
# Tomado de The Coding Train https://www.youtube.com/watch?v=IKB1hWWedMk
5-
class Terreno < Processing::App
6-
def settings
7-
size 800, 800, P3D
8-
end
9-
10-
def setup
11-
sketch_title 'Terreno'
12-
@w = 1400
13-
@h = 1100
14-
@scl = 30
15-
@col = @w/@scl
16-
@filas = @h/@scl
17-
@terreno = {}
18-
@mover = 0
19-
end
20-
21-
def draw
22-
background 0
23-
@mover -= 0.1
24-
yoff = @mover
25-
for y in 0..@filas
26-
xoff = 0
27-
for x in 0..@col
28-
@terreno["#{x}.#{y}"]= p5map noise(xoff,yoff), 0, 1, -65, 65
29-
xoff += 0.2
30-
end
31-
yoff += 0.2
32-
end
33-
stroke 255
34-
no_fill
35-
stroke 235, 69,129
36-
translate width/2, height/2
37-
rotate_x PI/3
38-
translate -@w/2, -@h/2
39-
for y in 0..@filas-1
40-
begin_shape(TRIANGLE_STRIP)
41-
for x in 0..@col
42-
vertex(x*@scl, y*@scl, @terreno["#{x}.#{y}"])
43-
vertex(x*@scl,(y+1)*@scl, @terreno["#{x}.#{y+1}"])
44-
end
45-
end_shape(CLOSE)
46-
end
47-
end
48-
end
1+
# After a sketch by Carlos Rocha, press mouse for smooth terrain
2+
WIDTH = 1_400
3+
HEIGHT = 1_100
4+
SCL = 30
5+
attr_reader :terrain, :rows, :columns, :mover, :hash_key
6+
7+
def settings
8+
size 800, 800, P3D
9+
end
10+
11+
def setup
12+
sketch_title 'Terreno'
13+
@columns = WIDTH / SCL
14+
@rows = HEIGHT / SCL
15+
@terrain = {}
16+
@hash_key = ->(x, y) { y * WIDTH + x }
17+
@mover = 0
18+
end
19+
20+
def draw
21+
background 0
22+
@mover -= 0.1
23+
yoff = mover
24+
(0..rows).each do |y|
25+
xoff = 0
26+
(0..columns).each do |x|
27+
terrain[hash_key.call(x, y)] = Vec3D.new(
28+
x * SCL, y * SCL,
29+
map1d(SmoothNoise.tnoise(xoff, yoff), -1.0..1.0, -65..65)
30+
)
31+
xoff += 0.2
32+
end
33+
yoff += 0.2
34+
end
35+
no_fill
36+
stroke 235, 69, 129
37+
translate width / 2, height / 2
38+
rotate_x PI / 3
39+
translate(-WIDTH / 2, -HEIGHT / 2)
40+
(0...rows).each do |y|
41+
begin_shape(TRIANGLE_STRIP)
42+
(0..columns).each do |x|
43+
terrain[hash_key.call(x, y)].to_vertex(renderer)
44+
terrain[hash_key.call(x, y.succ)].to_vertex(renderer)
45+
end
46+
end_shape
47+
end
48+
end
49+
50+
def mouse_pressed
51+
@smth = !smth
52+
end
53+
54+
private
55+
56+
def renderer
57+
@renderer ||= GfxRender.new(g)
58+
end

external_library/gem/geomerative/library/f_agent/f_agent.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ def initialize(loc:, increment:)
1212

1313
def motion
1414
@offset += increment
15-
loc.dist(Vec2D.new(noise(offset.x) * width, noise(offset.y) * height))
15+
hw = width / 2
16+
hh = height / 2
17+
loc.dist(Vec2D.new((noise(offset.x) + 1) * hw, (noise(offset.y) + 1) * hh))
1618
end
1719

1820
def display(xr:, yr:, m_point:)
1921
no_stroke
20-
fill(255, 73)
21-
dia = (150 / m_point) * 5
22+
fill(255, 100)
23+
dia = (150 / m_point) * 7
2224
# to get weird non-deterministic behaviour of original, created by use of
2325
# negative inputs to a random range surely not intended, use original:-
2426
# ellipse(loc.x + random(-xr, xr), loc.y + random(-yr, yr), dia, dia)
25-
xr *= -1 if xr < 0 # guards against an invalid hi..low range
26-
yr *= -1 if yr < 0
27+
xr *= -1 if xr.negative? # guards against an invalid hi..low range
28+
yr *= -1 if yr.negative?
2729
ellipse(loc.x + rand(-xr..xr), loc.y + rand(-yr..yr), dia, dia)
2830
end
2931
end

external_library/gem/geomerative/library/font_agent/font_agent.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
# frozen_literal: true
32
# FontAgent class handles motion and display
43
class FontAgent
@@ -12,9 +11,9 @@ def initialize(location:)
1211

1312
def motion
1413
noise_scale = map1d(mouse_x, (0..width), (0.001..0.01))
15-
noise_z = map1d(mouse_x, (0..height), (frame_count * 0.0003..frame_count * 0.02))
14+
noise_z = map1d(mouse_y, (0..height), (frame_count * 0.0003..frame_count * 0.02))
1615
noise_vector = loc * noise_scale * noise_z
17-
@mot = noise(noise_vector.x, noise_vector.y) * 53
16+
@mot = (noise(noise_vector.x, noise_vector.y) + 1) * 26.5
1817
end
1918

2019
def display(step:)

external_library/gem/geomerative/typo_deform.rb

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'geomerative'
2+
13
# --------- GEOMERATIVE EXAMPLES ---------------
24
# //////////////////////////////////////////////
35
# Title : TypoGeo_Deform
@@ -20,15 +22,13 @@
2022
# More info on these tutorials and workshops at :
2123
# www.freeartbureau.org/blog
2224
#
23-
require 'geomerative'
24-
load_library :font_agent
2525

26+
load_library :font_agent
2627
attr_reader :my_font, :my_group, :my_points, :my_text
2728
attr_reader :my_agents, :step, :stop_anime
2829

2930
def settings
3031
size(800, 350)
31-
smooth
3232
end
3333

3434
def setup

external_library/gem/geomerative/typo_extra_bright.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
# developed by Ricard Marxer.
1717
# http://www.ricardmarxer.com/geomerative/
1818
#
19-
# More info on these tutorials and workshops at :
20-
# www.freeartbureau.org/blog
2119
# translated for JRubyArt by Martin Prout
2220
require 'geomerative'
2321
load_library :f_agent
24-
2522
attr_reader :my_agents
2623

2724
def settings
@@ -40,7 +37,7 @@ def setup
4037
RCommand.set_segmentator(RCommand::UNIFORMLENGTH)
4138
@my_agents = my_font.to_group(my_text).get_points.map do |point|
4239
FontAgent.new(
43-
loc: Vec2D.new(point.x, point.y),
40+
loc: Vec2D.new(point),
4441
increment: Vec2D.new(x_incr, y_incr)
4542
)
4643
end

external_library/gem/geomerative/typo_merge.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def setup
5050

5151
def draw
5252
background(0, 50)
53-
displace_x = noise(xoff) * width
54-
displace_y = noise(yoff) * height
53+
displace_x = (noise(xoff) + 1) * width / 2
54+
displace_y = (noise(yoff) + 1) * height / 2
5555
@xoff += x_inc
5656
@yoff += y_inc
5757
translate(width / 2, height / 1.7)

processing_app/basics/math/additive_wave.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ def calculate_wave
3737
@theta += 0.02
3838

3939
# Set all height values to zero
40-
@y_values = Array.new @wave_width/@x_spacing, 0
40+
@y_values = Array.new @wave_width / @x_spacing, 0
4141

4242
# Accumulate wave height values
4343
max_waves.times do |j|
4444
x = @theta
4545
y_values.length.times do |i|
4646
# Every other wave is Math.cosine instead of Math.sine
47-
value = (j % 2) == 0 ? Math.sin(x) : Math.cos(x)
47+
value = j.even? ? Math.sin(x) : Math.cos(x)
4848
y_values[i] += value * amplitude[j]
4949
x += dx[j]
5050
end
@@ -57,7 +57,7 @@ def render_wave
5757
fill 255, 50
5858
ellipse_mode CENTER
5959
y_values.each_with_index do |y, i|
60-
ellipse i*@x_spacing, width/2+y, 16, 16
60+
ellipse i*@x_spacing, height / 2 + y, 16, 16
6161
end
6262
end
6363

0 commit comments

Comments
 (0)