Skip to content

Instantly share code, notes, and snippets.

@villares
Last active March 26, 2020 04:37
Show Gist options
  • Save villares/60b73ccf621c2dd3b274413e80fc2c9d to your computer and use it in GitHub Desktop.
Save villares/60b73ccf621c2dd3b274413e80fc2c9d to your computer and use it in GitHub Desktop.
# ported from https://www.openprocessing.org/sketch/862451
# by @takawo https://www.openprocessing.org/user/6533
# Missing drawingContext shadowColor shadowBlur :(
from random import choice
movers = []
mover_num = 350
pallete = ["#DADCDA", "#DE200C", "#3A6DA8", "#A8BACC",
"#0A1D4E", "#CD4645", "#C0AEB5", "#838CA9"]
def setup():
global ns, offset
size(800, 800)
# pixelDensity(1)
colorMode(HSB, 360, 100, 100, 100)
# angleMode(DEGREES) # unavailabe in Python mode
background(0, 0, 0)
ns = random(1000)
offset = width / 10
for i in range(mover_num):
x = random(offset, width - offset)
y = random(offset, height - offset)
movers.append(Mover(x, y))
# image(img, 0, 0, width, height)
def draw():
global ns
if frameCount % 1000 == 0:
ns = random(10000)
background(0, 0, 0)
noiseSeed(int(ns))
for i in range(5):
for m in movers:
m.update()
m.display()
class Mover:
def __init__(self, x, y):
self.pos = PVector(x, y)
self.prev_pos = self.pos.copy()
self.vel = PVector(0, 0)
self.noiseScale = 400
self.len = 1
self.strokeColor = choice(pallete)
# self.strokeBlurColor = self.strokeColor
def update(self):
n = int(noise(self.pos.x / self.noiseScale, self.pos.y / self.noiseScale) * 9)
angle = radians(n * 360 / 8) # adjusted for Python mode
self.vel = PVector(cos(angle) * self.len, sin(angle) * self.len)
self.pos.add(self.vel)
isBorder = False
if not (offset < self.pos.x < width - offset and
offset < self.pos.y < height - offset):
isBorder = True
if (random(100) < 1 or isBorder):
self.pos.x = random(offset, width - offset)
self.pos.y = random(offset, height - offset)
self.prev_pos = self.pos.copy()
self.strokeColor = choice(pallete)
self.strokeBlurColor = self.strokeColor
def display(self):
# drawingContext.shadowColor = self.strokeBlurColor
# drawingContext.shadowBlur = 5
stroke(self.strokeColor)
line(self.pos.x, self.pos.y, self.prev_pos.x, self.prev_pos.y)
self.prev_pos = self.pos.copy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment