class Nest { private Particle p; private int type, mem, age, hideCnt; private float radius; private color c, g; private boolean visible; private Vector rings; Nest() { p = phys.makeParticle(1, random(nestSize+10, width-nestSize-10), random(nestSize+10, height-nestSize-10), 0); p.makeFixed(); visible = false; type = NONE; radius = nestSize; c = nestColor; g = nestGlow; mem = age = hideCnt = 0; rings = new Vector(5, 0); } void update() { noFill(); for (int i = 0; i < rings.size(); i++) { Ring tmp = (Ring)rings.get(i); if ( tmp.finished ) rings.remove(i--); else { tmp.update(); tmp.render(); } } if ( visible ) { mem++; if ( mem > frameRate*3 ) { float rnd = random(1); if ( rnd < 0.25 ) prefer(NONE); else if ( rnd < 0.5 ) prefer(KICK); else if ( rnd < 0.75 ) prefer(SNARE); else prefer(HAT); mem = 0; } age++; if ( age() > 15 ) hide(); } else hideCnt++; } void move() { p.moveTo(random(radius+10, width-radius-10), random(radius+10, height-radius-10), 0); } void spawnRing() { rings.add(new Ring(x(), y())); } void tryCatch(Pulser puls) { if ( dist(puls.x(), puls.y(), x(), y()) < radius ) { totalCaught++; puls.caught = true; puls.setMood(GLEE); puls.tether(p); puls.detach(); score(puls); } } private void score(Pulser puls) { int points = 0; switch(puls.type) { case KICK: if ( type == KICK ) points = ( puls.isAttached() ? 150 : 400 ); else points = ( puls.isAttached() ? 100 : 300 ); break; case SNARE: if ( type == SNARE ) points = ( puls.isAttached() ? 175 : 300 ); else points = ( puls.isAttached() ? 125 : 200 ); break; case HAT: if ( type == HAT ) points = ( puls.isAttached() ? 200 : 250 ); else points = ( puls.isAttached() ? 150 : 150 ); break; } puls.score(points); } void prefer(int t) { type = t; switch(t) { case KICK : c = kickColor; g = kickGlow; break; case SNARE : c = snareColor; g = snareGlow; break; case HAT : c = hatColor; g = hatGlow; break; case NONE : c = nestColor; g = nestGlow; break; } } void hide() { visible = false; hideCnt = 0; } void show() { visible = true; age = 0; } boolean isVisible() { return visible; } boolean isHidden() { return !visible; } float hiddenFor() { return hideCnt/frameRate; } float radius() { return radius; } float age() { return age/frameRate; } float x() { return p.position().x(); } float y() { return p.position().y(); } void render() { float glow = glowIntensity; int glowSize = 10; float glowStep = 0.7f; noFill(); pushMatrix(); translate(x(), y()); if ( drawGlow ) { float rad = radius; for (int i = 1; i < glowSize; i++) { stroke(red(g), green(g), blue(g), glow/i); rad += glowStep; sept(rad); sept(rad*0.9f); diamond(rad/9, -45, 55); diamond(rad/9, 45, 55); mouth(rad); } rad = radius; for (int i = 1; i < glowSize; i++) { stroke(red(g), green(g), blue(g), glow/i); rad -= glowStep; sept(rad); sept(rad*0.9); diamond(rad/11, -45, 55); diamond(rad/11, 45, 55); mouth(rad); } } stroke(c); sept(radius); sept(radius*0.9f); diamond(radius/10, -45, 55); diamond(radius/10, 45, 55); mouth(radius); rotate(PI/7); if ( drawGlow ) { float rad = radius; for (int i = 1; i < glowSize; i++) { stroke(red(g), green(g), blue(g), glow/i); rad += glowStep; sept(rad); sept(rad*0.9f); } rad = radius; for (int i = 1; i < glowSize; i++) { stroke(red(g), green(g), blue(g), glow/i); rad -= glowStep; sept(rad); sept(rad*0.9); } } stroke(c); sept(radius); sept(radius*0.9f); popMatrix(); } private void mouth(float r) { float y = r * 0.72f; float x = r * 0.2f; line(-x, y, -x*0.45f, y*0.88f); line(x, y, x*0.45f, y*0.88f); line(-x*0.7f, y*0.94f, 0, y); line(x*0.7f, y*0.94f, 0, y); } class Ring { boolean finished; private float radius, endRadius, step, x, y; private color col; Ring(float _x, float _y) { x = _x; y = _y; radius = nestSize; endRadius = 1024; step = 10; col = g; } float radius() { return radius; } void update() { radius += step; } void render() { stroke(red(col), green(col), blue(col), 80); sept(radius, x, y); if ( radius >= endRadius ) finished = true; } } }