/* RUNNING UNDER PROCESSING 0098 A set of Particles move across the screen and leave traces. They have a random speed and direction. When they encounter Attractors, they get targeted to the attractors direction. Press 's' to show the attractors. Press 'p' to pause/continue the application. Press 'f' to show frame number. */ int nrOfParticles=10000; // PRESET ONE: // see "preset1.jpg" int nrOfAttractors=10; float attRadMin=0.05, attRadMax=0.3; float prtSpdMin=0.0005, prtSpdMax=0.001; float drawingStrength=0.3; boolean gColorGravity=false; boolean gTurnToColor=false; int wid=500, hei=1000; // PRESET TWO: // see "preset2.jpg" /* int nrOfAttractors=60; float attRadMin=0.01, attRadMax=0.1; float prtSpdMin=0.0009, prtSpdMax=0.0011; float drawingStrength=0.3; boolean gColorGravity=true; boolean gTurnToColor=false; int wid=1600, hei=800; */ // PRESET 3 /* int nrOfAttractors=80; float attRadMin=0.01, attRadMax=0.05; float prtSpdMin=0.0005, prtSpdMax=0.001; float drawingStrength=1.0; boolean gColorGravity=true; boolean gTurnToColor=true; int wid=500, hei=400; */ // main color ranges int colRLo=0, colRHi=128; int colGLo=20, colGHi=100; int colBLo=0, colBHi=25; float maxColorDiff; boolean showAttractors=false; boolean paused=false; Attractor[] attractor=new Attractor[nrOfAttractors]; Particle[] particle=new Particle[nrOfParticles]; void initAll() { colorMode(RGB,255); maxColorDiff=getColorDifference(color(colRLo,colGLo,colBLo),color(colRHi,colGHi,colBHi)); initAttractors(nrOfAttractors,width,height,attRadMin,attRadMax); initParticles(nrOfParticles,width,height,prtSpdMin,prtSpdMax); } void setup() { size(500,1000,P3D); initAll(); background(255); //loadPixels(); } void draw() { if (!paused) { //background(255); //updatePixels(); updateParticlePosition(nrOfParticles); drawParticles(nrOfParticles,drawingStrength); //loadPixels(); if (showAttractors) { drawAttractors(nrOfAttractors); } } } void mousePressed() { initAll(); background(255); } void keyPressed() { /* if (key=='s'||key=='S') { showAttractors=!showAttractors; } if (key=='p'||key=='P') { paused=!paused; println("Paused: "+paused); } if (key=='f'||key=='F') { println("Frame number: "+frameCount); } */ } // begin // LIBRARY PARTICLE // HOLDS: // // - class Particle(width,height) // position: x,m position limit: xMax, yMax [0..1] // movement: xm,ym // bounce: bouncyness in respect to border (true/false) // col: color of particle // - array particle with nrOfParticle items // - void initParticlePosition(arraylength,width,height) // - void updateParticles(arraylength) // - void drawParticles(arraylength) // LIBRARY PARTICLE // end // calculate shortest degree from deg1 to deg2 float getTurnDirection(float deg1, float deg2) { while (deg1>PI) { deg1-=TWO_PI; } while (deg2<-PI) { deg1+=TWO_PI; } while (deg2>PI) { deg2-=TWO_PI; } while (deg2<-PI) { deg2+=TWO_PI; } float rdeg=(deg1>deg2)?deg2-(deg1-TWO_PI):deg2-deg1; if (rdeg