Review

Commenting your code

Commenting your code

''' My Awesome Program
    Mark F. Russo
'''
from Processing import *

# This is a single-line comment
window(500, 500)

background(255, 0, 0) # End-of-line comment

Commenting your code

Comments should be brief and informative

# This loop calculates the sum of squares
# of all x values
s = 0
for x in xarray:
    s = s + x*x
print(s)

Commenting your code

Comments should NOT state the obvious

s = 0               # Init s to 0
for x in xarray:    # Loop over all x values
    s = s + x*x     # Add x*x to s
print(s)            # Print s

More Calico Processing

Calico Processing provides many useful utility functions

Random Numbers

Random Numbers

Draws an ellipse at a random location with a random fill color

from Processing import *
window(500, 500)

# Random color components
r = random(255)
g = random(255)
b = random(255)
fill(r, g, b)

# Random locations
x = random(500)
y = random(500)
ellipse(x, y, 50, 50)

Draw Text

Draw Text

from Processing import *
window(300, 300)

text("Moe", 10, 100)

textSize(20)
text("Larry", 10, 150)

textSize(30)
text("Curly", 10, 200)

Drawing Primitives in Processing

line( x1, y1, x2, y2 )

triangle( x1, y1, x2, y2, x3, y3 )

quad( x1, y1, x2, y2, x3, y3, x4, y4 )

rect( x, y, width, height )

ellipse( x, y, width, height )

Arcs

from Processing import *
window(500, 500)

# Draw an ellipse
strokeWeight(5)
stroke(200)
ellipse(250, 200, 300, 200)

# Draw an arc over the ellipse
stroke(255, 0, 0)
rads = radians(90)
arc(250, 200, 300, 200, 0, rads )

Shapes

Shapes

from Processing import *
window(500, 500)

fill(255, 0, 0)
curveTightness(0.3)

# Draw a heart
beginShape()
curveVertex(250, 400)
curveVertex(400, 200)
curveVertex(300, 150)
curveVertex(250, 200)
curveVertex(200, 150)
curveVertex(100, 200)
curveVertex(250, 400)
endShape(True)

Draw Images

Draw Images

from Processing import *

window(500, 400)
img = loadImage("natura.jpg")
image(img, 50, 40)

Examples

Assignment #1

http://cs.brynmawr.edu/Courses/cs110/fall2012/section002/Assignments/Assignment01.html

/

#