-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env jruby | ||
require 'picrate' | ||
|
||
Coord = Struct.new(:mx, :my, :mz, :az, :al) | ||
|
||
class ForD < Processing::App | ||
attr_reader :half_w, :half_h, :radius, :spin_x, :spin, :coords | ||
|
||
def settings | ||
size(480, 480, P3D) | ||
end | ||
|
||
def setup | ||
sketch_title '4D Simplex Noise Test' | ||
background(0) | ||
stroke(255) | ||
fill(32, 255, 64) | ||
@half_w = width * 0.5 | ||
@half_h = height * 0.5 | ||
@radius = height * 0.4 | ||
@spin_x = 0.0 | ||
@spin = 0.0 | ||
|
||
angle = ((1.0 + Math.sqrt(5)) / 2.0 - 1) * TWO_PI # Fibonacci distribution | ||
@coords = (0..2_000).map do |i| | ||
inc = Math.asin(i / 1_000.0 - 1.0) # inclination | ||
az = angle * i # azimuth | ||
# Too lazy to do this the right way... precalculating both the angles and the coordinates | ||
Coord.new.tap do |coord| | ||
push_matrix | ||
rotate_y(az) | ||
rotate_z(inc) | ||
translate(radius, 0, 0) | ||
coord.mx = model_x(0, 0, 0) * 0.007 | ||
coord.my = model_y(0, 0, 0) * 0.007 | ||
coord.mz = modelZ(0, 0, 0) * 0.007 | ||
coord.az = az | ||
coord.al = inc | ||
pop_matrix | ||
end | ||
end | ||
end | ||
|
||
def draw | ||
background(0) | ||
@spin -= (mouse_x - pmouse_x) * 0.0001 if mouse_pressed? | ||
@spin_x += spin | ||
@spin *= 0.98 | ||
push_matrix | ||
translate(half_w, half_h, -0) | ||
rotate_y(-spin_x) | ||
coords.each do |ci| | ||
push_matrix | ||
rotate_y(ci.az) | ||
rotate_z(ci.al) | ||
translate(radius, 0, 0) | ||
dst = (modelZ(0, 0, 0) + half_h) / 2 + 32 | ||
stroke(dst, dst * 0.5, dst * 0.25) | ||
# 4D Simplex noise(x, y, z, time) | ||
ang = noise(ci.mx, ci.my, ci.mz, frame_count * 0.007) * TWO_PI | ||
rotate_x(ang) | ||
line(0, 0, 0, 0, 15, 0) | ||
translate(0, 15, 0) | ||
rotate_x(-10) | ||
line(0, 0, 0, 0, 4, 0) | ||
rotate_x(20) | ||
line(0, 0, 0, 0, 4, 0) | ||
pop_matrix | ||
end | ||
pop_matrix | ||
end | ||
|
||
def mouse_pressed | ||
mode = NoiseMode::OPEN_SMOOTH | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
|
||
def mouse_released | ||
mode = NoiseMode::DEFAULT | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
end | ||
|
||
ForD.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
# Noise1D. | ||
# | ||
# Using 1D Perlin Noise to assign location. | ||
# frozen_string_literal: true | ||
require 'picrate' | ||
|
||
def setup | ||
sketch_title 'Noise 1D' | ||
@xoff = 0.0 | ||
@x_increment = 0.01 | ||
background 0 | ||
no_stroke | ||
end | ||
class Noise1D < Processing::App | ||
|
||
def draw | ||
fill 0, 10 | ||
rect 0, 0, width, height | ||
n = noise(@xoff) * width | ||
@xoff += @x_increment | ||
fill 200 | ||
ellipse n, height / 2, 64, 64 | ||
end | ||
def setup | ||
sketch_title 'Noise 1D' | ||
@xoff = 360 | ||
@x_increment = 0.01 | ||
background 0 | ||
no_stroke | ||
end | ||
|
||
def draw | ||
fill 0, 10 | ||
rect 0, 0, width, height | ||
n = noise(@xoff) * width | ||
@xoff += @x_increment | ||
fill 200 | ||
ellipse n, height / 2, 64, 64 | ||
end | ||
|
||
def settings | ||
size 640, 360 | ||
def mouse_pressed | ||
mode = NoiseMode::OPEN_SMOOTH | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
|
||
def mouse_released | ||
mode = NoiseMode::DEFAULT | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
|
||
def settings | ||
size 640, 360 | ||
end | ||
end | ||
|
||
Noise1D.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,58 @@ | ||
# frozen_string_literal: true | ||
require 'picrate' | ||
# Noise Wave | ||
# by Daniel Shiffman. | ||
# | ||
# Using Perlin Noise to generate a wave-like pattern. | ||
# by Daniel Shiffman. | ||
# | ||
# Using Perlin Noise to generate a wave-like pattern. | ||
class NoiseWave < Processing::App | ||
|
||
attr_reader :yoff # 2nd dimension of perlin noise | ||
attr_reader :yoff # 2nd dimension of perlin noise | ||
|
||
def setup | ||
sketch_title 'Noise Wave' | ||
@yoff = 0.0 | ||
end | ||
def setup | ||
sketch_title 'Noise Wave' | ||
@yoff = 0.0 | ||
end | ||
|
||
def draw | ||
background(51) | ||
fill(255) | ||
# We are going to draw a polygon out of the wave points | ||
begin_shape | ||
xoff = 0 # Option #1: 2D Noise | ||
# xoff = yoff # Option #2: 1D Noise | ||
# Iterate over horizontal pixels | ||
(0..width).step(10) do |x| | ||
# Calculate a y value according to noise, map to | ||
y = map1d(noise(xoff, yoff), (0..1.0), (200..300)) # Option #1: 2D Noise | ||
# y = map1d(noise(xoff), (0..1.0), (200..300)) # Option #2: 1D Noise | ||
# Set the vertex | ||
vertex(x, y) | ||
# Increment x dimension for noise | ||
xoff += 0.05 | ||
def draw | ||
background(51) | ||
fill(255) | ||
# We are going to draw a polygon out of the wave points | ||
begin_shape | ||
xoff = 0 # Option #1: 2D Noise | ||
# xoff = yoff # Option #2: 1D Noise | ||
# Iterate over horizontal pixels | ||
(0..width).step(10) do |x| | ||
# Calculate a y value according to noise, map to | ||
y = map1d(noise(xoff, yoff), (0..1.0), (200..300)) # Option #1: 2D Noise | ||
# y = map1d(noise(xoff), (0..1.0), (200..300)) # Option #2: 1D Noise | ||
# Set the vertex | ||
vertex(x, y) | ||
# Increment x dimension for noise | ||
xoff += 0.05 | ||
end | ||
# increment y dimension for noise | ||
@yoff += 0.01 | ||
vertex(width, height) | ||
vertex(0, height) | ||
end_shape(CLOSE) | ||
end | ||
# increment y dimension for noise | ||
@yoff += 0.01 | ||
vertex(width, height) | ||
vertex(0, height) | ||
end_shape(CLOSE) | ||
end | ||
|
||
def settings | ||
size(640, 360) | ||
end | ||
|
||
def mouse_pressed | ||
mode = NoiseMode::OPEN_SMOOTH | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
|
||
def mouse_released | ||
mode = NoiseMode::DEFAULT | ||
sketch_title mode.description | ||
noise_mode mode | ||
end | ||
|
||
def settings | ||
size(640, 360) | ||
end | ||
end | ||
|
||
NoiseWave.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.