class Nest { private Particle p; private int type, mem; private float radius; private color c, g, tc; Nest(float x, float y) { p = phys.makeParticle(1, x, y, 0); p.makeFixed(); type = NONE; radius = nestSize; c = color(255, 255, 255); g = color(255, 162, 0); tc = color(0); mem = 0; } void kill() { p.kill(); } void update() { 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; } } void tryCatch(Pulser puls) { if ( dist(puls.x(), puls.y(), x(), y()) < radius ) { puls.caught = true; puls.setMood(GLEE); puls.tether(p); puls.detach(); score(puls); } } void score(Pulser puls) { totalCaught++; int points = ( puls.type == type ? 200 : 100 ); puls.points = points; score += points; } void prefer(int t) { type = t; switch(t) { case KICK : tc = kickColor; break; case SNARE : tc = snareColor; break; case HAT : tc = hatColor; break; } } float radius() { return radius; } float age() { return p.age()/frameRate; } float x() { return p.position().x(); } float y() { return p.position().y(); } void render() { float glow = glowIntensity - 30; int glowSize = 7; float glowStep = 0.4f; stroke(c); noFill(); pushMatrix(); translate(x(), y()); sept(radius); sept(radius*0.9f); diamond(radius/10, -45, 55); diamond(radius/10, 45, 55); mouth(radius); if ( type != NONE ) thought(radius, 255); 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); if ( type != NONE ) thought(rad, glow/i); } 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); if ( type != NONE ) thought(rad, glow/i); } } rotate(PI/7); stroke(c); sept(radius); sept(radius*0.9f); 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); } } 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); } private void thought(float r, float a) { pushMatrix(); if ( x() < width - 200 ) translate(r*1.1f, r*0.4f); else translate(-r*1.1f, r*0.4f); rotate(-PI/15); pent(r/10); if ( x() < width - 200 ) translate(32, -20); else translate (-32, -20); pent(r/7); if ( x() < width - 200 ) translate(45, -55); else translate(-45, -55); rotate(TWO_PI/15); pent(r/2); stroke(red(tc), green(tc), blue(tc), a); r /= 4; sept(r); pushMatrix(); rotate(PI); pent(r*0.26, -r*0.55, 0); line(-r*0.55, r*0.26, -r*0.55, -r*0.26*0.8); pent(r*0.26, r*0.55, 0); line(r*0.55, r*0.26, r*0.55, -r*0.26*0.8); popMatrix(); beginShape(); vertex(r*-0.65f, r*0.35f); vertex(r*0.65f, r*0.35f); vertex(r*0.5625f, r*0.55f); vertex(0, r*0.8f); vertex(r*-0.5625f, r*0.55f); endShape(CLOSE); popMatrix(); } }