// animate on curvePoint // by mikkel . crone . koser // http://proce55ing.beyondthree.com // or more at : www.beyondthree.com // oct. 2003 // click to add new shapes // 'b' to blur image // 'c' to clear canvas final int WIDTH = 400; final int HEIGHT = 400; final int DEPTH = 400; Color bg; // Fly fly[]; int POP = 50; int POPvisible = 1; void setup(){ size(WIDTH, HEIGHT); ellipseMode(CENTER_DIAMETER); noStroke(); lights(); bg = new Color(0, 0, 0); background(bg.getRed(), bg.getGreen(), bg.getBlue()); // populate flys fly = new Fly[POP]; for(int i = 0; i < POP; i++){ fly[i] = new Fly(WIDTH, HEIGHT, DEPTH, random(0.02, 0.01)); } } void loop(){ for(int i = 0; i < POPvisible; i++){ fly[i].update(); } } void mousePressed(){ POPvisible++; } void keyPressed(){ if(key == 'c'){ background(bg.getRed(), bg.getGreen(), bg.getBlue()); } } class Fly{ int w, h, d; int x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; float step = 0f; float speed; float x, y, z; Color rgb = new Color(255, 255, 255); //Color rgb = new Color((int)random(220, 255),(int)random(180, 220), (int)random(0)); Fly(int wwidth, int hheight, int ddepth, float sspeed){ w = wwidth; h = hheight; d = ddepth; speed = sspeed; x1 = x2 = x3 = x4 = w/2; y1 = y2 = y3 = y4 = h/2; z1 = z2 = z3 = z4 = d*3; makeNewCurve(); } void makeNewCurve(){ x1 = x2; x2 = x3; x3 = x4; x4 = (int)random(0, w); y1 = y2; y2 = y3; y3 = y4; y4 = (int)random(0, h); z1 = z2; z2 = z3; z3 = z4; z4 = (int)random(0, d); } void update(){ step += speed; if(step >= 1f){ makeNewCurve(); step = 0f; } x = curvePoint(x1, x2, x3, x4, step); y = curvePoint(y1, y2, y3, y4, step); z = curvePoint(z1, z2, z3, z4, step); push(); translate(x, y, -z/2); fill(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), rgb.getAlpha()); sphere(50); //ellipse(x, y, 100, 100); pop(); } }