''' 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
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)
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
Calico Processing provides many useful utility functions
print(items)
h = height() w = width()
rad = radians(degrees)
r = random(min, max) print(r)
r = random(max) print(r)
randomSeed(seed)
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)
textSize(20)
text( "x-axis", 100, 150 )
text( "y-axis", 10, 10, 100, 30 )
from Processing import * window(300, 300) text("Moe", 10, 100) textSize(20) text("Larry", 10, 150) textSize(30) text("Curly", 10, 200) |
![]() |
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 )
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 ) |
![]() |
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)
|
![]() |
img = loadImage("natura.jpg")
image(img, 50, 40)
image(img, 50, 40, 25, 25)
from Processing import * window(500, 400) img = loadImage("natura.jpg") image(img, 50, 40) |
![]() |
/
#