// amoebaAbstract_01 // Copyright 2003 Marius Watz // http://www.evolutionzone.com/ // // Abstract computational animation for the exhibition "Abstraction // Now", Künstlerhaus Vienna, 29.08-28.09 2003. // // You are allowed to play with this code as much as you like, but // you may not publish pieces based directly on it. The Vec2D class // can be used freely in any context. // int num,cnt,px,py; Particle[] particles; boolean initialised=false,clearScreen=false; float lastRelease=-1; void setup() { size(700,400); background(255); smooth(); rectMode(CENTER_DIAMETER); ellipseMode(CENTER_DIAMETER); cnt=0; num=50; particles=new Particle[num]; for(int i=0; i0) particles[i].update(); } void mousePressed() { if(!initialised) { clearScreen=true; initialised=true; } float time=millis(); if(lastRelease!=-1 && (time-lastRelease)<200) { background(255); for(int i=0; i50) dirMod=-dirMod; dir+=dirMod; vD.set(speed,0); vD.rotate(radians(dir+90)); stateCnt=10+int(random(5)); if(random(100)>90) stateCnt+=30; } void update() { age--; if(age>=30) { vD.rotate(radians(1)); vD.mult(1.01f); } v.add(vD); fill(255-age,0,100,150); push(); translate(v.x,v.y); rotate(radians(dir)); rect(0,0,1,1); pop(); if(age==0) { if(random(100)>50) fill(200,0,0,200); else fill(00,200,255,200); float size=2+random(4); if(random(100)>95) size+=5; ellipse(v.x,v.y,size,size); } if(v.x<0 || v.x>width || v.y<0 || v.y>height) age=0; if(age<30) { stateCnt--; if(stateCnt==0) { initMove(); } } } } // General vector class for 2D vectors class Vec2D { float x,y; Vec2D(float _x,float _y) { x=_x; y=_y; } Vec2D(Vec2D v) { x=v.x; y=v.y; } void set(float _x,float _y) { x=_x; y=_y; } void set(Vec2D v) { x=v.x; y=v.y; } void add(float _x,float _y) { x+=_x; y+=_y; } void add(Vec2D v) { x+=v.x; y+=v.y; } void sub(float _x,float _y) { x-=_x; y-=_y; } void sub(Vec2D v) { x-=v.x; y-=v.y; } void mult(float m) { x*=m; y*=m; } void div(float m) { x/=m; y/=m; } float length() { return sqrt(x*x+y*y); } float angle() { return atan2(y,x); } void normalise() { float l=length(); if(l!=0) { x/=l; y/=l; } } Vec2D tangent() { return new Vec2D(-y,x); } void rotate(float val) { // Due to float not being precise enough, double is used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmpx=x*cosval - y*sinval; double tmpy=x*sinval + y*cosval; x=(float)tmpx; y=(float)tmpy; } }