# BoxRotator.py

from Processing import *

window(500, 500)

boxes = []
rectMode(CENTER)

class Rotator:
    def __init__(self, x, y):
        self.x = x          # Position
        self.y = y
        self.angle = 0.0    # Angle of rotation

    def step(self):
        self.angle = self.angle + 0.05

    def display(self):
        fill(200)
        pushMatrix()
        translate(self.x, self.y)
        rotate(self.angle)
        rect(0, 0, 20, 20)
        popMatrix()

# Create a new box and add to the master list
def createBox(o, e):
    x, y = mouseX(), mouseY()
    b = Rotator(x, y)
    boxes.append( b )

# Draw all boxes
def draw(o, e):
    background(0)
    for b in boxes:
        b.step()
        b.display()

# Create a new box whenever the mouse is clicked
onMousePressed += createBox

# Draw all
frameRate(30)
onLoop += draw
loop()
