Skip to content

Commit ca67bbd

Browse files
committed
Simplex Noise
1 parent 1b69061 commit ca67bbd

File tree

14 files changed

+32
-39
lines changed

14 files changed

+32
-39
lines changed

external_library/gem/pbox2d/lib/surface.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def initialize(app)
2121
# This has to go backwards so that the objects bounce off the top of the
2222
# surface. This "edgechain" will only work in one direction!
2323
(width + 10).step(-10, -5) do |x|
24-
# Doing some stuff with perlin noise to calculate a surface that points
24+
# Doing some stuff with OpenSimplex2 noise to calculate a surface that points
2525
# down on one side and up on the other
2626
if x > width / 2
27-
@y = 100 + (width - x) * 1.1 + map1d(noise(xoff), (0..1.0), (-80..80))
27+
@y = 100 + (width - x) * 1.1 + map1d(noise(xoff), (-1.0..1.0), (-80..80))
2828
else
29-
@y = 100 + x * 1.1 + map1d(noise(xoff), (0..1.0), (-80..80))
29+
@y = 100 + x * 1.1 + map1d(noise(xoff), (-1.0..1.0), (-80..80))
3030
end
3131
# Store the vertex in screen coordinates
3232
surface << Vec2.new(x, y)
33-
# Move through perlin noise
33+
# Move through simplex noise
3434
xoff += 0.1
3535
end
3636
# Build an array of vertices in Box2D coordinates
@@ -133,4 +133,4 @@ def make_body(x, y, r)
133133
body.set_linear_velocity(Vec2.new(rand(-10..10), rand(5..10)))
134134
body.set_angular_velocity(rand(-10..10))
135135
end
136-
end
136+
end

external_library/gem/toxiclibs/simulation/simplex_noise_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'propane'
44
require 'toxiclibs'
55
# Test and SimplexNoise Karsten Schmidt
6+
# Better to use Built in OPenSimplex2 in propane
67
class SimplexNoiseTest < Propane::App
78
attr_reader :noise_dimension, :noise_offset
89

external_library/java/grafica/default_plot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setup
2020
points = GPointsArray.new(POINTS)
2121

2222
POINTS.times do |i|
23-
points.add(i, 10 * noise(0.1 * i))
23+
points.add(i, 5 * (noise(0.1 * i) + 1))
2424
end
2525

2626
# Create a new plot and set its position on the screen

external_library/java/hemesh/hec_from_network.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setup
2626
network = WB_Network.new
2727
vertices.each_with_index do |vertex, i|
2828
# compromise on 2D noise for elegance and simplicity
29-
network.addNode(vertex[0], vertex[1], vertex[2], noise(0.1 * rand(3), 0.1 * i))
29+
network.addNode(vertex[0], vertex[1], vertex[2], (noise(0.1 * rand(3), 0.1 * i) + 1) / 2)
3030
end
3131
grid(40, 40) do |i, j|
3232
network.addConnection(i + 41 * j, i + 1 + 41 * j) if rand(100) > 30

external_library/java/hemesh/twin_iso.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setup
2424
(0..RES).each do |j|
2525
val = []
2626
(0..RES).each do |k|
27-
val << 2.1 * noise(0.35 * i, 0.35 * j, 0.35 * k)
27+
val << 1.05 * SmoothNoise.noise(0.35 * i, 0.35 * j, 0.35 * k) + 1
2828
end
2929
valu << val
3030
end

processing_app/basics/math/noise4_tap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def draw
5858
dst = (g.model_z(0, 0, 0) + half_h) / 2 + 32
5959
stroke(dst, dst * 0.5, dst * 0.25)
6060
# 4D Simplex noise(x, y, z, time)
61-
ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI
61+
ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * PI
6262
rotate_x(ang)
6363
line(0, 0, 0, 0, 15, 0)
6464
translate(0, 15, 0)

processing_app/basics/math/noise_1_d.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,28 @@
33
require 'propane'
44

55
class Noise1D < Propane::App
6+
attr_reader :smth
67

78
def setup
89
sketch_title 'Noise 1D'
910
@xoff = width / 2
1011
@x_increment = 0.01
1112
background 0
1213
no_stroke
14+
@smth = false
1315
end
1416

1517
def draw
1618
fill 0, 10
1719
rect 0, 0, width, height
18-
n = noise(@xoff) * width
20+
n = smth ? SmoothNoise.noise(@xoff) * width : noise(@xoff) * width
1921
@xoff += @x_increment
2022
fill 200
2123
ellipse n, height / 2, 64, 64
2224
end
2325

2426
def mouse_pressed
25-
mode = NoiseMode::SMOOTH_OPEN
26-
noise_mode mode
27-
sketch_title "#{mode.description}"
28-
end
29-
30-
def mouse_released
31-
mode = NoiseMode::DEFAULT
32-
noise_mode(mode)
33-
sketch_title "#{mode.description}"
27+
@smth = !smth
3428
end
3529

3630
def settings

processing_app/basics/math/noise_2_d.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ def draw
1717
background 0
1818
load_pixels
1919
xoff = 0.0
20-
detail = map1d(mouse_x, (0..width), (0.1..0.6))
21-
noise_detail(8, detail)
2220
(0...width).each do |x|
2321
xoff += @increment
2422
yoff = 0.0
2523
(0...height).each do |y|
2624
yoff += @increment
27-
bright = noise(xoff, yoff) * 255
25+
bright = (noise(xoff, yoff) + 1) * 128
2826
pixels[x + y * width] = color(bright)
2927
end
3028
end

processing_app/basics/math/noise_3_d.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def draw
2626
yoff = 0.0
2727
(0...height).each do |y|
2828
yoff += increment
29-
bright = noise(xoff, yoff, @zoff) * 255
29+
bright = (noise(xoff, yoff, @zoff) + 1) * 128
3030
pixels[x + y * width] = color(bright, bright, bright)
3131
end
3232
end

processing_app/basics/math/noise_image.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def draw
1919
load_pixels
2020
grid(500, 500) do |x, y|
2121
if smth
22-
col = SmoothNoise.noise(SCALE * x, SCALE * y) > 0 ? 255 : 0
22+
col = SmoothNoise.noise(SCALE * x, SCALE * y).positive? ? 255 : 0
2323
else
24-
col = noise(SCALE * x, SCALE * y) > 0 ? 255 : 0
24+
col = noise(SCALE * x, SCALE * y).positive? ? 255 : 0
2525
end
2626
pixels[x + width * y] = color(col, 0, 0)
2727
end

0 commit comments

Comments
 (0)