/** * Some experiments with Boids. * Nick Selvaggio * Based on pseudocode from http://www.vergenet.net/~conrad/boids/pseudocode.html * 1.05.10 **/ //a collection of palettes. I am using http://www.colourlovers.com/ color[] blues = {#00C5CC, #7CFFF4, #74E4FF, #BEFFEF, #A1F1FF, #FF0000, #FC0000}; color[] light = {#D8EBE0, #BADEDD, #C9BAA1}; color[] smlBlue = {#00C5CC}; color[] blacks = {#000000}; color[] reds = {#FF0000, #F60000}; color[] pie_crust = {#310015, #1C0B12, #C4B482, #0D0207, #17070E}; color[] nothing_changes = {#70074B, #110240, #FF0000, #FFD000}; color[] classic_holiday = {#5F0606, #DA1717, #FFF5D6, #035F0B, #013A06}; color[] palette = blues; int t; ArrayList boids; int numBoids = 50; //multiplers. int m1; //lets set this sketch up. void setup() { size(940,209, P2D); frameRate(20); background(255); t=0; //start time at 0. m1 = 1; createUniverse(); } //------------------------------------ void createUniverse() { createBoids(); //our initialize_positions routine. } //------------------------------------ //Keep it moving... void draw() { fill(0, 5); noStroke(); rect(0, 0, width, height); //background(0); //keep flowing out boids every 100 units of time. if(t > 100) { createUniverse(); t = 0; } else { drawBoids(); t++; } } void createBoids() { boids = new ArrayList(); Particle p; for(int i = 0; i width || p.loc.x < 0) { v.x = -p.vel.x*2; } if(p.loc.y > height || p.loc.y < 0) { v.y = -p.vel.y*2; } return v; } //shot out to jared tarbell... my favorite artist! color someColor() { return palette[int(random(palette.length))]; } //------------------------------------ void mousePressed() { //scatter the flock OR don't scatter the flock. // m1 = -m1; // createUniverse(); //saveFrame("boid-####.png"); }