Objektorientiertes Animieren #01 (zielstrebig) in Processing
Powered by Processing.js
Der Sketch
Gizmo giz[] = new Gizmo[30];
void setup () {
size (550, 200);
background (76, 76, 75);
stroke (236);
for (int i=0; i < giz.length; i++) {
float x = random (width);
float y = random (height);
giz[i] = new Gizmo (x, y);
}
}
void draw () {
for (int i=0; i < giz.length; i++) {
giz[i].move ();
point (giz[i].position.x, giz[i].position.y);
}
}class Gizmo {
PVector position;
PVector target;
Gizmo (float theX, float theY) {
position = new PVector (theX, theY);
target = new PVector ();
newRandomTarget ();
}
void move () {
PVector step = new PVector ();
step.set (position);
step.sub (target);
step.div (40);
position.sub (step);
if (position.dist (target) < 3) {
newRandomTarget ();
}
}
void newRandomTarget () {
target.x = random (width);
target.y = random (height);
}
}