// // from processing.unlekker.net // Particle gas[]; int num; int colors[][],colNum,colBG; boolean doSaveFrame=false,doSetBackground=true; float rotOffs=4,speed=1; float centerX,centerY; void setup() { size(600,400); num=30; smooth(); // rectMode(CENTER_RADIUS); colors=new int[100][3]; addColor(255,255,255); addColor(255,0,0); addColor(150,30,0); addColor(255,200,0); addColor(0,200,255); addColor(0,20,50); addColor(0,200,50); colBG=((int)random(10000))%colNum; centerX=width/2+random(200)-100; centerY=height/2+random(150)-75; gas=new Particle[num]; for(int i=0; iwidth || v.y<0 || v.y>height || age==0) init(); fill(colors[col][0],colors[col][1],colors[col][2], 240); rect(v.x,v.y, rad,rad); } } // Vec2D - simple 2D vector class // processing.unlekker.net 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) { // Floats are not precise enough, so doubles are 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; } }