/* * ARTS 102 - Aesthetics of the Algorithmic Image * Johannes Goerz (johannes.goerz@gmail.com) * 2005-12-04 */ Tentacle[] t; int maxtentacles, framecounter, life; int[][] startpoints; boolean showcenter; void setup() { // general procesing parameters size(600,600); smooth(); background(0); framerate(25); noStroke(); // animation parameters maxtentacles = 8; life = 40; showcenter = false; // setup starting positions; startpoints = new int[4][2]; startpoints[0][0] = 80; startpoints[0][1] = 80; startpoints[1][0] = width-80; startpoints[1][1] = height-80; startpoints[2][0] = 80; startpoints[2][1] = height-80; startpoints[3][0] = width-80; startpoints[3][1] = 80; // create tentacles t = new Tentacle[maxtentacles]; for(int i = 0; i < maxtentacles; i++) { createNewTentacle( i ); } } void draw() { noStroke(); // fade background every 5 frames if(framecounter%5==0) { fill(0,5); rect(0,0,width,height); } framecounter++; // move tentacles Vector massvector = getMassPosition(); for(int i = 0; i < t.length; i++) { t[i].move( massvector ); if( showcenter ) { stroke(0,0,255,50); line(t[i].position.x, t[i].position.y, massvector.x, massvector.y); noStroke(); } } } void createNewTentacle( int id ) { int _point = int(random(0,startpoints.length)); if (_point > startpoints.length -1 ) { _point = startpoints.length - 1; } t[id] = new Tentacle( startpoints[_point][0] + int( random(-20,20) ), startpoints[_point][1] + int( random(-20,20) )); t[id].initialize( id, color(255,100), int(life + random(life)), true); } Vector getMassPosition() { Vector mass = new Vector(); mass.init(0,0); for(int i = 0; i < t.length; i++) { mass.add(t[i].position); } mass.setLength( mass.l / t.length ); if( showcenter ) { // draw center of mass fill(255,0,0,100); ellipse(mass.x,mass.y,10,10); } return mass; } void mousePressed() { noLoop(); } void mouseReleased() { loop(); }