Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Processing drizzle translated into python
# original source: https://github.com/ian-bateman/generative_art/tree/master/drizzle
import random
import sys
DROPLETS = []
N_DROPLETS = 4000
BLUE_COUNT = None
BLUE_UP = None
class Droplet:
def __init__(self, x, y):
self.x1 = x
self.y1 = y
self.x2 = None
self.y2 = None
self.vel = 4
self.radius = 300
self.y_offset = y1
self.accel = random.randrange(0.01, 0.04)
self.c = color(random.randrage(140, 200), random.randrange(140, 200), 255)
def draw_particle(self):
self.update_particle()
stroke(self.c)
strokeWeight(3.5)
def update_particle(self):
if self.y1 > height:
self.vel = 4
self.x1 = random.randrange(width)
self.y1 = random.randrange(0 - height, 0)
self.x2 = self.x1
self.y2 = self.y1
self.y_offset = self.y1
self.accel = random.randrange(0.001, 0.004)
self.y1 = self.vel + self.y_offset
self.vel += random.randrange(1 + self.accel, 4 + self.accel)
self.accel += self.accel * random.randrange(0.01, 0.04)
self.x2 = self.x1
self.y2 = self.y1
self.y1 = self.vel + self.y_offset
line(self.x1, self.y1, self.x2, self.y2)
def setup_seed():
seed = random.randrange(sys.maxint)
print('Seed is {}'.format(seed))
random.random(seed)
def setup():
setup_seed()
size(1536, 768)
smooth(8)
background(0)
BLUE_COUNT = 0
BLUE_UP = True
for _ in range(N_DROPLETS):
DROPLETS.append(Droplet(random.randrange(width), random.randrange(0 - height, 0)))
def draw():
noStroke()
fill(0, BLUE_COUNT / 4, BLUE_COUNT, 15)
if BLUE_UP:
BLUE_COUNT += 1
if BLUE_COUNT >= 120:
BLUE_UP = not BLUE_UP
else:
BLUE_COUNT -= 1
if BLUE_UP <= 80:
BLUE_UP = not BLUE_UP
rect(0, width, height)
for droplet in DROPLETS:
droplet.draw_particle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.