//import processing.opengl.*; // Flocking // Daniel Shiffman // Demonstration of Craig Reynolds' "Flocking" behavior // See: http://www.red3d.com/cwr/ // Rules: Cohesion, Separation, Alignment // Click mouse to add boids into the system // Created 2 May 2005 Flock flock; // PImage video; int scl;//= 8; PVector center; PFont f; float buildingWidth = 650; float buildingHeight = 420; float windowSize = 25; float gapSize = 15; float verticalGap = 10; boolean debug = true; boolean showvalues = false; Path path; void setup() { setupScrollbars(); f = loadFont("Arial-BoldMT-12.vlw"); center = new PVector(width/2,height/2); size(800,600); //colorMode(RGB,255,255,255,100); newPath(); flock = new Flock(); //Add an initial set of boids into the system for (int i = 0; i < 150; i++) { flock.addBoid(new Boid(new PVector(width/2,height/2),2.0f,0.05f)); } smooth(); } float now = 0.0f; void draw() { //background(0); background(255); smooth(); flock.run(); drawScrollbars(); //Bldg test = new Bldg(); //test.render(); path.display(); //stroke(255,0,0,100); //strokeWeight(1); int windowCount = 0; int x = 0; while(x < buildingWidth) { x += windowSize; if(x < buildingWidth) { windowCount++; } x += gapSize; } // count the number of windows vertically int rowCount = 0; int y = 0; while(y < buildingHeight) //y<450 { y += windowSize; ///y +=25 if(y < buildingHeight) { rowCount++; } y += verticalGap; } float xoffset = (windowCount*windowSize + (windowCount-5)*gapSize); float yoffset = (rowCount*windowSize + (rowCount)*verticalGap); float cy = yoffset - buildingHeight/1.3; for(int i = 0; i < rowCount; i++) { float cx = xoffset - buildingWidth/1.36; for(int j = 0; j < windowCount; j++) { stroke(0); strokeWeight(1); //fill(0); rect(cx, cy, windowSize, windowSize); cx += windowSize + gapSize; } cy += windowSize + verticalGap; } } void newPath() { // A path is a series of connected points // A more sophisticated path might be a curve path = new Path(); path.addPoint(75,75); path.addPoint(width-75,75); path.addPoint(width-75,height-75); path.addPoint(75,height-75); path.addPoint(75,75); } // Add a new boid into the System void mousePressed() { int acolor; int asize; float s = random(100); if (s > 10){ //make it gray acolor=color(random(100),random(10,200),random(200)); } else{ acolor=0; } float r = random(100); if (r > 90){ //make big man asize=1; } else{ //make little man asize=0; } flock.addBoid(new Boid(new PVector(mouseX,mouseY),3.0f,1.05f,acolor,asize)); }