I started with the idea of galaxy, particles and petals, and wanted to create a combination of those. The most interesting experience when creating this piece is that it trains me to think about how each frame is going to be different from other frame. I enjoyed playing with the code. However, I think the coding could still be pushed more to create more varied designs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | /* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/699*@* */ /* !do not delete the line above, required for linking your tweak if you upload again */ // 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/ // 2008.04.04 PhG : much faster in P3D mode : now ok with 10'000 stars ! // keyboard interaction : use arrow keys to alter the galaxy import gifAnimation.*; // http://www.extrapixel.ch/processing/gifAnimation/ int nFramesInLoop = 30; // for lenticular export, change this to 10! int nElapsedFrames; boolean bRecording; String myGalaxy = "galaxy"; float pi=4*atan(1); int stars=20000; // only ... int Rmax=200; // galaxy radius float speed= 0.4; //rotation speed // stars follow elliptic orbits around the center float eratio=.75; // 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(250,93,159); //yellow stars void setup(){ size(500,500,P3D); bRecording = false; nElapsedFrames = 0; frameRate (nFramesInLoop); background(0); //back to black speed=speed/frameRate; // 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); } // gifExport = new gifAnimation.GifMaker(this, "galaxy.gif"); // gifExport.setRepeat(0); } void keyPressed() { // Press a key to export frames to the output folder bRecording = true; nElapsedFrames = 0; } void draw() { // Compute a percentage (0...1) representing where we are in the loop. float percentCompleteFraction = 0; if (bRecording) { percentCompleteFraction = (float) nElapsedFrames / (float)nFramesInLoop; } else { float modFrame = (float) (frameCount % nFramesInLoop); percentCompleteFraction = modFrame / (float)nFramesInLoop; } // Render the design, based on that percentage. renderMyDesign (percentCompleteFraction); // If we're recording the output, save the frame to a file. if (bRecording) { saveFrame("output/"+ myGalaxy + "-loop-" + nf(nElapsedFrames, 4) + ".png"); nElapsedFrames++; if (nElapsedFrames == nFramesInLoop) { bRecording = false; } } } void renderMyDesign (float percent) { background(241,255,142); //back to black stroke(col); for (int i =0; i< stars; i++){ float r=radius[i]; float a=angle[i]+speed; //increment angle angle[i]=a; float x = r*sin(a); float y = r*eratio*cos(a); float b = r*etwist; float x1 = r*cos(b); // float y1 = r*eratio*sin(b); float s = sin(b); float c = cos(b); //point(cx1+s*x1,cy+c*x-s*y); //a bit of trigo //point(cx+s*x,cy+s*x1-c*y); //a bit of trigo //point(cx+s*x,cy+s*x1-c*y); //a bit of trigo point(cx+s*x,cy+s*x1-c*y); //a bit of trigo //point(cx+s*y,cy1+c*x1-s*y); //a bit of trigo point(cx+s*x*6/5,cy+c*x1-s*y); //a bit of trigo // ellipse(cx+s*x,cy+c*x-s*y, 2, 3); } } |