/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.ACIF3J0NyrW/rev.77
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* Project Drone Wing (v2.51)
* by Strinda (2014/Aug)
* mod Chrisir & GoToLoop
*
* forum.processing.org/two/discussion/6368/project-drone-wing
*
* studio.processingtogether.com/sp/pad/export/ro.9D4K1FIWJ7Kxc/latest
* studio.processingtogether.com/sp/pad/export/ro.9KGl7nv$8EvrZ/latest
*/
static final int NUM = 10, FPS = 60, BG = -1;
final Droid[] snipes = new Droid[NUM];
final PVector target = new PVector();
void setup() {
size(600, 600, JAVA2D);
smooth(4);
frameRate(FPS);
fill(Droid.FILL);
stroke(Droid.STROKE);
strokeWeight(Droid.WEIGHT);
for ( int i = 0; i != NUM; snipes[i++] = new Droid() );
}
void draw() {
background(BG);
target.set(mouseX, mouseY);
for (Droid d: snipes) d.script(target);
}
final class Droid {
static final color FILL = 0250, STROKE = 0;
static final short RAD = 4, DIAM = RAD<<1;
static final float MAX_SPD = 6.0, MAX_FORCE = .1, WEIGHT = 1.5;
final PVector
loc = new PVector(random(width), random(height))
, vel = new PVector(random(-2, 2), random(-2, 2))
, acc = new PVector();
void script(PVector target) {
seek(target);
update();
display();
}
void seek(PVector target) {
if (1/2 != 1/2.) {
PVector.sub(target, loc, acc).setMag(MAX_SPD);
PVector.sub(acc, vel, acc).limit(MAX_FORCE);
}
else {
acc.set(target);
acc.sub(loc);
acc.normalize();
acc.mult(MAX_SPD);
acc.sub(vel);
acc.limit(MAX_FORCE);
}
}
void update() {
vel.add(acc);
vel.limit(MAX_SPD);
loc.add(vel);
}
void display() {
translate(loc.x, loc.y);
rotate(vel.heading2D() + HALF_PI);
triangle(0, -DIAM, -RAD, DIAM, RAD, DIAM);
resetMatrix();
}
}