static int NUMBEROFRECTANGLE = 5; static int NUMBEROFBOID = 120; static int BOIDPERRECTANGLE; static float RECTLARGEURMAX = 450.0f; static float RECTLARGEURMIN = 220.0f; static float COHESIONDISTANCE = 60.0f; static float REPULSIONDISTANCE = 59.0f; static float COHESIONRATE = 0.024f; static float COLLISIONRATE = 0.09f; static float RECTANGLEINFLUENCE = 0.001f; static int lineOpacity = 0; static int brushOpacity = 100; static int BGOpacity = 1; static float pictureVelocity = 0.12f; static PImage backgroundPict; static float randomColor = 50.0f; int pictID; Rectangle[] rectangleList; Boid[] boidList; CollisionPixel[][] pixelGrid; float gametime = 0.0f; static float changeTime = 15.0f; void setup() { pictID = int(random(0,3)); size(700,500); background(255); //grid creation BOIDPERRECTANGLE = int((float)NUMBEROFBOID / (float)NUMBEROFRECTANGLE); switchPict(); if(random(0,1) >= 0.24) { lineOpacity = 10; } else { lineOpacity = 0; } pixelGrid = new CollisionPixel[width][height]; for(int i = 0; i < width; ++i) { for(int j = 0; j < height; ++j) { pixelGrid[i][j] = new CollisionPixel(); } } //rectangles creation createRectangle(); //boid creation boidList = new Boid[NUMBEROFBOID]; for(int i = 0; i < NUMBEROFBOID; ++i) { int rectangleID = int(((float)i/(float)NUMBEROFBOID) * NUMBEROFRECTANGLE); boidList[i] = new Boid(rectangleList[rectangleID],boidList, i); } } void draw() { //noStroke(); //fill(255,255,255,BGOpacity); //rect(0,0,width,height); gametime += 0.016f; if(gametime >= changeTime)//there is changing { gametime = 0.0f; if(random(0,1) >= 0.5) { } else { setRectangleParam(); } } for(int i = 0; i < boidList.length; ++i) { boidList[i].computeForces(); boidList[i].update(); boidList[i].drawing(); } } void createRectangle() { //rectangles creation rectangleList = new Rectangle[NUMBEROFRECTANGLE]; for(int i = 0; i < NUMBEROFRECTANGLE; ++i) { rectangleList[i] = new Rectangle(i, pixelGrid); } } void setRectangleParam() { for(int i = 0; i < NUMBEROFRECTANGLE; ++i) { rectangleList[i].setNewParameter(); } } void switchPict() { backgroundPict = loadImage("data/map" + pictID + ".jpg"); pictID = (pictID + 1) % 3; } //keyboard control void keyPressed() { if (keyCode == ENTER) { setup(); } if (keyCode == DOWN) { setRectangleParam(); } if (keyCode == UP) { switchPict(); } if (keyCode == LEFT) { lineOpacity = constrain(lineOpacity - 5,0,100); } if (keyCode == RIGHT) { lineOpacity = constrain(lineOpacity + 5,0,100); } }