Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions examples/handbook/centipede/centipede.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Adapted from

/**
* Synthesis 3: Motion and Arrays
* Centipede by Ariel Malka (www.chronotext.org)
* p. 372
*/
"""


node_length = 30
node_size = node_length-1
n_nodes = 70
nodes = []
delay = 20.0
col_head = color(255, 0, 0)
col_body = color(0)

def setup():
size(600, 600)
smooth()
noStroke()

global x,y
x = width/2
y = height/2

r1 = 10
r2 = 100
dr = r2-r1
D = 0.0

for i in range(n_nodes):
r = sqrt(r1 * r1 + 2.0 * dr * D)
d = (r - r1) / dr

nodes.append((x - sin(d) * r, y + cos(d) * r))

D += node_length


def draw():
background(204)

# Set the position of the head
setTarget(mouseX, mouseY)

# Draw the head
fill(col_head)
ellipse(nodes[0][0], nodes[0][1], node_size, node_size)

# Draw the body
fill(col_body)
for x,y in nodes[1:]:
ellipse(x,y, node_size, node_size)


def setTarget(tx, ty):
# Motion interpolation for the head
global x,y
x += (tx - x) / delay
y += (ty - y) / delay
nodes[0] = (x,y)

# Constrained motion for the other nodes
for i in range(1,n_nodes):
dx = nodes[i - 1][0] - nodes[i][0]
dy = nodes[i - 1][1] - nodes[i][1]
length = sqrt(sq(dx) + sq(dy))
nodes[i] = (nodes[i - 1][0] - (dx/length * node_length),
nodes[i - 1][1] - (dy/length * node_length))


65 changes: 65 additions & 0 deletions examples/handbook/cylinder/cylinder.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Draw a cylinder centered on the y-axis, going down from y=0 to y=height.
# The radius at the top can be different from the radius at the bottom,
# and the number of sides drawn is variable.



def setup() :
size(400, 400, P3D)
global my_shape
my_shape = drawCylinder(10, 180, 200, 16) # Draw a mix between a cylinder and a cone
#my_shape = drawCylinder(70, 70, 120, 16) # Draw a cylinder
#my_shape = drawCylinder(0, 180, 200, 4) # Draw a pyramid


def draw():
background(0)
lights()
translate(width / 2, height / 2)
rotateY(mouseX * PI / width)
rotateZ(mouseY * -PI / height)

fill(255, 255, 255)
translate(0, -40, 0)
shape(my_shape)

def drawCylinder(topRadius, bottomRadius, tall, sides):
noStroke()
cone = createShape(PShape.GROUP)
angle = 0
angleIncrement = TWO_PI / sides
cylinder = createShape(PShape.QUAD_STRIP)
for i in range(sides+1):
#normal(cos(angle),sin(angle),0)
cylinder.vertex(topRadius*cos(angle), 0, topRadius*sin(angle))
cylinder.vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle))
angle += angleIncrement
cylinder.end()
cone.addChild(cylinder)
# If it is not a cone, draw the circular top cap
if (topRadius != 0):
angle = 0
top = createShape(PShape.TRIANGLE_FAN)

# Center point
top.vertex(0, 0, 0)
for i in range(sides+1):
top.vertex(topRadius * cos(angle), 0, topRadius * sin(angle))
angle += angleIncrement
top.end()
cone.addChild(top)
# If it is not a cone, draw the circular bottom cap
if (bottomRadius != 0):
angle = 0
bottom = createShape(PShape.TRIANGLE_FAN)

# Center point
bottom.vertex(0, tall, 0)
for i in range(sides+1):
bottom.vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle))
angle += angleIncrement

bottom.end()
return cone


12 changes: 12 additions & 0 deletions examples/handbook/ellipse_sketch/ellipse_sketch.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
size(100, 100)
background(0)
noStroke()
smooth()
fill(242, 204, 47, 160)
ellipse(47, 36, 64, 64)
fill(174, 221, 60, 160)
ellipse(90, 47, 64, 64)
fill(116, 193, 206, 160)
ellipse(57, 79, 64, 64)


10 changes: 10 additions & 0 deletions examples/handbook/hsb_test/hsb_test.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Change the saturation and brightness, hue constant
size(100, 100)
colorMode(HSB)
for i in range(100):
for j in range(100):
stroke(132, j*2.5, i*2.5)
point(i, j)


11 changes: 11 additions & 0 deletions examples/handbook/lines/lines.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
size(100, 100)
background(56, 90, 94)
smooth(4)
x = 0
strokeWeight(12)
for i in range(51,256,51):
stroke(242, 204, 47, i)
line(x, 20, x+20, 80)
x += 20


22 changes: 22 additions & 0 deletions examples/handbook/mouse_interaction/mouse_interaction.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Draw a sphere on top of a box and moves the coordinates with the mouse
# Press a mouse button to turn on the lights
def setup():
size(400, 400, P3D)

def draw():
background(0);
if mousePressed == True:
# If the mouse is pressed,
lights(); # turn on lights
noStroke()
pushMatrix()
translate(mouseX, mouseY, -500)
rotateY(PI / 6) # Rotate around y-axis
box(400, 100, 400) # Draw box
pushMatrix()
popMatrix()
translate(0, -200, 0) # Position the sphere
sphere(150) # Draw sphere on top of box
popMatrix()


33 changes: 33 additions & 0 deletions examples/handbook/waves/waves.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Adapted from
/**
* Synthesis 1: Form and Code
* Riley Waves by Casey Reas (www.processing.org)
* p. 151
*
* Step 3, values are modified to create a new pattern.
*/
"""

size(1200, 280)
background(255)
smooth()
noStroke()
#fill(0)
angle = PI
angle2 = PI
magnitude = 3

for i in range(-magnitude,height+magnitude,12):
angle2 = angle
fill(0)
beginShape(TRIANGLE_STRIP)
for x in range(0,width+1,8):
y = i + (sin(angle)* magnitude)
angle += PI/24.0
y2 = i+4 + (sin(angle+PI/12)* magnitude)
vertex(x, y)
vertex(x, y2)
endShape()


21 changes: 21 additions & 0 deletions examples/misc/boxandsphere/boxandsphere.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def setup():
size(200,200, P3D)
noLoop()

def draw():
# clear the whole screen
background(200)
lights()
noStroke()
background(200)
pushMatrix()
fill(255,255,0)
translate(130,130)
rotate(PI/6,1,1,0)
box(50)
popMatrix()
fill(255,0,255)
translate(60, 50)
sphere(50)


27 changes: 27 additions & 0 deletions examples/misc/circles/circles.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def setup():
size(300,300)
smooth()
global l
l = []

def mousePressed():
l.append ([mouseX, mouseY, 1])

def mouseDragged():
l.append ([mouseX, mouseY,1])

def draw():
fill(0,10)
noStroke()
rect(0,0,width,height)
stroke(255)
nl = l[:]
l[:]=[]
for x,y,w in nl:
gs = 255-w
if gs<0: continue
stroke(gs)
ellipse(x,y,w,w)
l.append([x,y,w+2])


9 changes: 9 additions & 0 deletions examples/misc/coordsystem/coordsystem.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
size(200,200)
rectMode(CENTER)
rect(100,100,20,100)
ellipse(100,70,60,60)
ellipse(81,70,16,32)
ellipse(119,70,16,32)
line(90,150,80,160)
line(110,150,120,160)

19 changes: 19 additions & 0 deletions examples/misc/falloff/falloff.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

def setup():
size(200, 200, P3D)
noStroke()

def draw():
background(200)
if mousePressed: lightFalloff(1,0,1e-4)
pointLight(255,255,255,100,100,50)
nx = 6
ny = 6
for i in range(nx):
for j in range(ny):
pushMatrix()
translate((i+0.5)*width/nx,(j+0.5)*height/ny)
sphere(10)
popMatrix()


9 changes: 9 additions & 0 deletions examples/misc/fonttest/fonttest.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


size(200,200)
font = createFont("Times New Roman", 20)
textFont(font)
textAlign(CENTER,CENTER)
text("The quick brown\nfox jumps over\nthe lazy dogs", width/2, height/2)


44 changes: 44 additions & 0 deletions examples/misc/fpstest/fpstest.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from random import randint

# Choose the total number of bouncing balls
nballs = 150
balls = [()]*nballs

def setup():
size(400,400)
noStroke()
ellipseMode(CENTER)
# generate n balls with random positions, sizes, speeds and colors
for i in range(nballs):
# position
x, y = randint(20, 380), randint(20, 380)
# speed
dx, dy = randint(1, 4), randint(-4, -1)
# radius
r = randint(10, 20)
# color
c = color(randint(10, 255),randint(10, 255),randint(10, 255))
balls[i] = (x,y,dx,dy,r,c)


def draw():
# fade the last frame by drawing background in transparent color
fill(255,50)
rect(0,0,width,height)
# draw/bounce balls
for i, ball in enumerate(balls):
x,y,dx,dy,r,c = ball
fill(c)
x += dx
y += dy
diam = r/2
if constrain(x, diam, 400 - diam) != x:
dx *= -1
if constrain(y, diam, 400 - diam) != y:
dy *= -1
balls[i] = x,y,dx,dy,r,c
ellipse(x,y,r,r)
fill(0)
text("fps: %3d"%frameRate,0,20)


4 changes: 4 additions & 0 deletions examples/misc/helloworld/helloworld.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
size(300,300)
textFont(createFont("Times", 36))
textAlign(CENTER)
text("Hello world", width/2, height/2)
17 changes: 17 additions & 0 deletions examples/misc/helloworldrot/helloworldrot.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def setup():
size(300,300, P3D)
textFont(createFont("Times New Roman", 36))
textAlign(CENTER,CENTER)
global ang
ang = 0

def draw():
global ang
background(0,0,0)
fill (255)
translate (width/2, height/2)
rotateZ (ang)
ang += 0.01
text("Hello world", 0, 0)


Loading