// // floq experiment // // start in debug mode or not boolean debugKeys = false; int fadeInFrames = 60; int initBoidNum = 300; boolean drawBox = false; boolean doSmooth = true; int bgColor = 64; int normalBoidColor = 160; int meColor = 32; int anotherColor = 255; // length of trail points list int trailPoints = 20; // how often trail points are created // (this influences trail length just as much as trailPoints) int trailFrameInterval = 8; float starDistance = 100; // time in seconds after one star is created before a new star can appear int starDelay = 5; float starGrowRate = 1.0; int starFadeDelay = 90; // frame counter, transient stuff int frames = 0; int lastStarTime; Boid me, another; FloqList floq; ArrayList selfTrailPoints; ArrayList stars; void addTrailPoint(PVector p) { // check if list is full, remove to preserve length if (selfTrailPoints.size() > trailPoints) selfTrailPoints.remove(0); selfTrailPoints.add(p); } void drawTrails() { PVector p1; int tr=32, tg=32, tb=32, ta=0; beginShape(); stroke(tr, tg, tb, ta); strokeWeight(2); noFill(); for (int i=0; i < selfTrailPoints.size(); i++) { stroke(tr, tg, tb, ta); strokeWeight(i*0.25); p1 = (PVector)selfTrailPoints.get(i); curveVertex(p1.x, p1.y, p1.z); //tr += 2; //tr = min(255, tr); ta += 2; //tg -= 2; //tb -= 2; //println(tr + ", " + tg + ", " + tb); } // fade in last vert stroke(tr, tg, tb, 0); curveVertex(me.pos.x, me.pos.y, me.pos.z); endShape(); } class Star { PVector pos; int startTime; float size = 1; int alpha = 255; // star size should vary int variance = 0; Star(PVector p, int t) { pos = p; startTime = t; //println("star @ " + pos); variance = (int)random(60); } void draw() { // if before fade delay, keep growing if ( frames < startTime + starFadeDelay - variance ) { size += starGrowRate; } else { // else fade out // if alpha is <= 0, we'll be removed during next drawStars() alpha -= 1; } beginShape(LINES); strokeWeight(1); // 4-pointed star with alpha'd tips stroke(255, alpha); vertex(pos.x, pos.y, pos.z); stroke(255, 0); vertex(pos.x + size, pos.y, pos.z); stroke(255, alpha); vertex(pos.x, pos.y, pos.z); stroke(255, 0); vertex(pos.x - size, pos.y, pos.z); // stroke(255, alpha); vertex(pos.x, pos.y, pos.z); stroke(255, 0); vertex(pos.x, pos.y + size, pos.z); stroke(255, alpha); vertex(pos.x, pos.y, pos.z); stroke(255, 0); vertex(pos.x, pos.y - size, pos.z); // endShape(); } } void drawStars() { for (int i=0; i star delay, // make new star if (d <= starDistance && frames >= lastStarTime + starDelay * 30) { lastStarTime = frames; // determine midpoint between me and another mid = another.pos.get(); mid.sub(me.pos); mid.normalize(); mid.mult(d / 2); mid.add(me.pos); stars.add(new Star(mid, frames)); } } class FloqList { ArrayList boids; FloqList(int n) { boids = new ArrayList(); for(int i=0; i