# BoxMover.py

from Processing import *

window(500, 500)

boxes = []
rectMode(CENTER)

class Mover:
    def __init__(self, x, y):
        self.x = x          # Position
        self.y = y
        self.vx = -5.0       # Velocity
        self.vy = 5.0

    def step(self):
        #self.x = self.x + self.vx
        #self.y = self.y + self.vy
        w, h = width(), height()
        self.x = (self.x + self.vx + w) % w
        self.y = (self.y + self.vy + h) % h

    def display(self):
        fill(200)
        rect(self.x, self.y, 20, 20)

# Create a new box and add to the master list
def createBox(o, e):
    x, y = mouseX(), mouseY()
    b = Mover( 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()
