// amoebaAbstract_02 // 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; Particle[] particles; boolean changeDirection,doSave=false; String filename; int cnt; void setup() { // size(1024,768); size(700,400); background(100,20,0); smooth(); noStroke(); rectMode(CENTER_DIAMETER); ellipseMode(CENTER_DIAMETER); num=10; particles=new Particle[num]; for(int i=0; i50) dirMod=-dirMod; dir+=dirMod; dirD=random(0.75)+0.1; if(random(100)>50) dirD=-dirD; if(index<2) dirD*=0.5; vD.set(speed,0); vD.rotate(radians(dir+90)); changeCnt=20; if(index==TRIANGLES) stateCnt=60+int(random(60)); else stateCnt=100+int(random(250)); if(random(100)>90) stateCnt+=250; if(cnt>0 && index==TRIANGLES) { fill(255,255,255,50); ellipse(v.x,v.y,30,30); } else if(cnt>0 && index==CROSSES) { fill(255,255,255,50); ellipse(v.x,v.y,30,30); } else if(index%2==1) { fill(255,255,255,160); ellipse(v.x,v.y,index*1.5+2,index*1.5+2); } else { fill(255,255,255,160); push(); translate(v.x,v.y); rotate(radians(dir+90)); rect(0,0,14,4); rect(0,0,4,14); pop(); } } void update() { cnt++; changeCnt--; if(index==CROSSES) { dir+=int(random(5))*5-10; vD.set(speed,0); vD.rotate(radians(dir)); } else if(index!=TRIANGLES) { dir+=dirD; vD.set(speed,0); vD.rotate(radians(dir)); } v.add(vD); if(v.x<0) v.x+=width; else if(v.x>width) v.x-=width; if(v.y<0) v.y+=height; else if(v.y>height) v.y-=height; stateCnt--; if(stateCnt==0) initMove(); } void draw() { if(index==TRIANGLES && cnt%10!=0) return; else if(index==CROSSES && cnt%10!=0) return; // if(i%2==0) fill(100,100,120,10); if(index==TRIANGLES) fill(255,255,0);//fill(186,214,22,150); else if(index==CROSSES) fill(255,50,100);//, 150); else if(index%2==0) fill(255,220,0,70); //fill(240,10,100,50); else fill(255,0,180,50); push(); translate(v.x,v.y); rotate(radians(dir)); if(index==TRIANGLES) triangle(-3.5,-3.5, 3.5,-3.5, 0,3.5); else if(index==CROSSES) {rect(0,0,8,2); rect(0,0,2,8);} else rect(0,0,2,index*1.5+2); pop(); } } // 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; } }