Or something like this perhaps:
Code:
PImage bg;
Box box;
void setup()
{
size(400,400);
rectMode(CENTER);
smooth();
box = new Box(0,0);
background(255);
bg = new PImage(width,height);
fillImage(bg,color(255));
}
void mousePressed()
{
loadPixels();
bg.pixels = pixels;
bg.updatePixels();
}
void draw()
{
background(bg);
box.setPosition(mouseX,mouseY);
box.draw();
}
class Box
{
int x, y, w, h, direction;
float rotation;
Box(int x, int y)
{
this(x,y,20,20);
}
Box(int x, int y, int w, int h)
{
this.direction = (int)random(2)==0?-1:1;
setPosition(x,y);
this.w = w;
this.h = h;
}
void setPosition(int x, int y)
{
this.x = x;
this.y = y;
}
void draw()
{
rotation+=0.05*direction;
noFill();
stroke(0);
pushMatrix();
translate(x,y);
rotate(rotation);
rect(0,0,w,h);
popMatrix();
}
}
void fillImage(PImage img, color c)
{
for(int i = 0; i < img.pixels.length; i++)
img.pixels[i] = c;
img.updatePixels();
}
-seltar