/* * ARTS 102 - Aesthetics of the Algorithmic Image * Johannes Goerz (johannes.goerz@gmail.com) * 2005-12-04 */ class Tentacle { int id, lifetime, lifespan; float angle; color c; boolean organic; Vector movement, position; Tentacle(int _x, int _y ) { this.position = new Vector(); this.movement = new Vector(); this.position.init(_x, _y); } // initialize tentacle's properties void initialize(int _id, color _c, int _lifetime, boolean _organic) { this.angle = random(-1,1)*2*PI; this.c = _c; this.lifetime = _lifetime; this.lifespan = _lifetime; this.id = _id; this.organic = _organic; } void draw() { // drawing tentacle segment float obj_size = this.lifetime * 0.5; fill(this.c); ellipse( this.position.x, this.position.y, obj_size, obj_size ); } void move(Vector target) { if(this.lifetime >= 0 && this.position.x >= 0 && this.position.x <= width && this.position.y >= 0 && this.position.y <= height) { this.movement.reset(); float rand = 0; if( organic ) { rand = random(-1,1) * PI/8; } this.movement.add( target ); this.movement.sub( this.position ); this.angle = (this.movement.angle + 3 * this.angle)/4 + rand; this.movement.setLength( this.movement.l / 30 ); this.movement.setAngle( this.angle ); this.position.add( this.movement ); this.draw(); this.lifetime--; } else { // when lifetime is over or running out of window -> DIE!!! this.die(); } } void die() { createNewTentacle( this.id ); } }