Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Py Processing Scripts - Basics
radius = 100
def setup():
size(800, 600)
background(255)
smooth()
noStroke()
fill(0, 0, 200)
frameRate(100)
def draw():
background(255)
xpos = radius
ypos=0
pushMatrix()
translate(width/2, height/2) #recenters coor
rotate(radians(frameCount % 360))
ellipse(0,0,3,3) #centerpoint for visual referencing
ellipse(xpos, ypos, 20, 20)
ellipse(-1*xpos, ypos, 20, 20)
popMatrix()
w, h = 1000, 800
class Ball(object):
def __init__(self,_id, _x, _y, _vx=0, _vy=0):
self.x, self.y = _x, _y
self.vx, self.vy = _vx, _vy
self.id = _id
def move(self):
self.x += self.vx
self.y += self.vy
#x out of bounds
if self.x > width:
self.x=0
self.y=0
if self.y > height:
self.y=0
self.x=0
def display(self):
ellipse(self.x, self.y, 20,20)
b1 = Ball(0,0,0,5,5)
def setup():
size(w,h)
background(127)
smooth()
noStroke()
def draw():
global b1
background(127)
b1.move()
b1.display()
fill_val = color(126)
def draw():
fill(fill_val)
rect(25, 25, 50, 50)
def keyPressed():
global fill_val
if key == CODED:
if keyCode == UP:
fill_val = (fill_val + 5)%255
elif keyCode == DOWN:
fill_val = (fill_val - 5)%255
else:
fill_val = random(255)
radius = 100
num_pods = 10
def setup():
size(800, 600)
background(255)
smooth()
noStroke()
fill(0, 0, 200)
def draw():
background(255)
xpos = radius
ypos=0
translate(width/2, height/2) #recenters coords
ellipse(0,0,3,3) #centerpoint for visual referencing
for pod in range(12): #a pod is a capsule or a gondola
xpos = radius * sin(pod*TWO_PI/num_pods)
ypos = radius * cos(pod*TWO_PI/num_pods)
ellipse(xpos, ypos, 20, 20)
w, h = 1000, 800
class Ball(object):
def __init__(self,_id, _x, _y, _vx=0, _vy=0):
self.x, self.y = _x, _y
self.vx, self.vy = _vx, _vy
self.id = _id
def move(self):
self.x += self.vx
self.y += self.vy
#x out of bounds
if self.x > width:
self.x=0
self.y=0
if self.y > height:
self.y=0
self.x=0
def display(self):
ellipse(self.x, self.y, 20,20)
num_balls = 16
balls = [Ball(x,0,0,5,5) for x in range(num_balls)]
a = 0
active_balls = []
def setup():
size(w,h)
background(127)
smooth()
noStroke()
def draw():
global balls, active_balls, a
background(127)
if a < num_balls:
if not frameCount%10:
active_balls.append(balls[a])
a+=1
print(len(active_balls), a)
for b in active_balls:
b.move()
b.display()
# Have a Grid of small squares.
# Color them in the grayscale.
# Color changes over time, per Perlin Noise.
w, h = 800, 800
side = 10
spacing = 5
noise_scale = 0.03
def setup():
size(w,h)
noStroke
background(200)
def draw():
if not (frameCount % 20):
for col in range(0, h, side+spacing):
for row in range(0, w, side+spacing):
noiseVal = noise(col * noise_scale, row * noise_scale)
fill(noise(noiseVal) * 255 * noise(frameCount*noise_scale) )
rect(col, row, side, side)
w, ht = 1000, 800
def setup():
size(w, ht)
background(255) #white
noFill()
def draw():
x = random(width)
y = random(height)
r = random(500)
#Draw Random circles repeatedly
ellipse(x,y, r, r)
radius = 100
def setup():
size(800, 600)
background(255)
smooth()
noStroke()
fill(0, 0, 200)
def draw():
if (frameCount % 10 == 0):
fill(frameCount * 7 % 255, frameCount * 5 % 255,
frameCount * 7 % 255)
xpos = radius
pushMatrix()
translate(width/2, height/2) #recenters coor
rotate(radians(frameCount % 360))
ellipse(300, 150, 20, 20)
popMatrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment