// Spiral Galaxy Simulation // author : Philippe Guglielmetti (Dr. Goulu www.goulu.net) // 2008.04.03 PhG : my first processing program ! // converted from my LUA/Demoniak 3D demo V 1.0 // see http://3dmon.wordpress.com/2007/08/26/simulation-de-galaxie-spirale/ float pi=4*atan(1); int stars=1000; // only ... int Rmax=100; // galaxy radius float speed=0.1; // rotation speed // stars follow elliptic orbits around the center float eratio=.7; // ellipse ratio float etwist=8.0/Rmax; // twisting factor (orbit axes depend on radius) float []angle=new float[stars]; float []radius=new float[stars]; float cx; float cy; //center color col=color(255,255,192); // yellow stars void setup(){ background(0); // back to black size(int(Rmax*3), int(Rmax*2)); // begin in the center cx = width/2; cy = height/2; // itit stars for (int i=0; i< stars; i++){ angle[i]= random(0,2*pi); radius[i]=random(1,Rmax); } } void draw(){ background(0); // back to black stroke(col); for (int i =0; i< stars; i++){ float r=radius[i]; float a=angle[i]+speed/r; // increment angle angle[i]=a; float x = r*sin(a); float y= r*eratio*cos(a); float b=r*etwist; float s=sin(b); float c=cos(b); point(cx+s*x+c*y,cy+c*x-s*y); // a bit of trigo } }