Gizmo giz[] = new Gizmo[700];
PImage typo;
void setup () {
size (320, 240);
stroke (0);
background (255);
typo = loadImage ("background.jpg");
for (int i=0; i < giz.length; i++) {
float x = random (width);
float y = random (height);
giz[i] = new Gizmo (x, y);
}
}
void draw () {
noStroke ();
fill (255, 30);
rect (0, 0, width, height);
stroke (0);
for (int i=0; i < giz.length; i++) {
giz[i].move ();
int x = int (giz[i].position.x);
int y = int (giz[i].position.y);
color pixel = typo.get (x, y);
if (brightness (pixel) < 40) {
point (x, y);
}
}
}
class Gizmo {
PVector position;
PVector direction;
float spin = 0.15;
Gizmo (float theX, float theY) {
position = new PVector (theX, theY);
direction = new PVector ();
direction.x = random (-1, 1);
direction.y = random (-1, 1);
}
void move () {
direction.x += random (-spin, spin);
direction.y += random (-spin, spin);
direction.normalize ();
position.add (direction);
if (position.x < 0 || position.x > width) {
direction.x *= -1;
}
if (position.y < 0 || position.y > height) {
direction.y *= -1;
}
}
}