P5 library - Randomness and Perlin noise
Randomness 1D
...
from p5 import *
from random import random
def setup():
size(350, 350)
background(240)
random_noise_1d()
def random_noise_1d():
px, py = None, None
for x in range(0, width, 2):
y = height / 2 + (random() - 0.5) * 2 * height / 3
if px is not None:
line(px, py, x, y)
px, py = x, y
run()
Perlin noise in 1D
...
from p5 import *
from random import random
SEED = random() * 1000
OCTAVES = 4
DROP = 0.5
STEP = 0.02
def setup():
size(350, 350)
background(240)
noise_seed(SEED)
noise_detail(OCTAVES, DROP)
perlin_noise_1d()
def perlin_noise_1d():
px, py = None, None
for x in range(0, width, 2):
y = map(noise(x * STEP), 0, 1, height * 1/3, height * 2/3)
if px is not None:
line(px, py, x, y)
px, py = x, y
run()
Randomness 2D
...
from p5 import *
from random import randint
N = 100
def setup():
size(350, 350)
color_mode(HSB)
no_stroke()
w = width / N
for c in range(N):
for r in range(N):
hue = randint(0, 360)
fill(hue, 100, 100)
rect(c * w, r * w, w, w)
run()
Perlin noise in 2D
...
from p5 import *
from random import randint
N = 100
SEED = randint(0, 100)
OCTAVES = 4
DROP = 0.5
MULT = 0.04
def setup():
size(350, 350)
noise_seed(randint(0, 100))
noise_detail(OCTAVES, DROP)
def draw():
perlin_noise_2d()
def perlin_noise_2d():
color_mode(HSB)
no_stroke()
w = width / N
hue = noise(frame_count * 0.01) * 360
t = frame_count / 100
for c in range(N):
for r in range(N):
saturation = 50 * noise(t * c * MULT, t * r * MULT) * 50
brightness = noise(t * r * MULT, t * c * MULT) * 100
fill(hue, saturation, brightness)
rect(c * w, r * w, w, w)
run()