class DrawLine { DrawPoint a; DrawPoint b; DrawLine( DrawPoint a, DrawPoint b ) { // Hold references, not copies, // So colors update in unison. this.a = a; this.b = b; } boolean IsDead() { return ( a.IsDead() || b.IsDead() ); } void AddToShape() { // Not Cached, so Points are free to move. // Get slightly offset points, for style. PVector axis = PVector.sub( a.pos, b.pos ); PVector aEnd = PVector.add( b.pos, PVector.mult( axis, LINE_SPACE ) ); PVector bEnd = PVector.add( b.pos, PVector.mult( axis, 1 - LINE_SPACE ) ); stroke( a.col ); vertex( aEnd.x, aEnd.y, aEnd.z ); stroke( b.col ); vertex( bEnd.x, bEnd.y, bEnd.z ); } } class DrawPoint { PVector pos; color col; color rgb; int a; Timer lifetime; DrawPoint( PVector pos, color rgb, int a ) { this.pos = pos; this.rgb = rgb; this.a = a; this.col = color( red(rgb), green(rgb), blue(rgb), a ); lifetime = new Timer( POINT_LIFETIME ); } void Update( int delta ) { lifetime.Update( delta ); this.col = color( red(rgb), green(rgb), blue(rgb), (int)(a * (1 - lifetime.Percent()) ) ); } boolean IsDead() { return lifetime.IsDone(); } }