-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessing_Swarms.pde
73 lines (64 loc) · 1.6 KB
/
processing_Swarms.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licence LGPL (see Licence.txt for details)
int MAX_MOVEMENT = 3;
int SIGHT_RADIUS = 100;
int LIGHT_RADIUS = 150;
int LIGHT_PROXIMITY = 20;
Maxim maxim;
AudioPlayer bgSound;
AudioPlayer fishSound;
PImage bg;
PImage redFish;
PImage greenFish;
PImage resetIcon;
Array agents;
Light light = new Light();
int[] bgColour = new int[]{0, 0, 255};
void setup() {
//sounds from http://www.freesound.org/
maxim = new Maxim(this);
bgSound = maxim.loadFile("waves.wav");
bgSound.setLooping(true);
fishSound = maxim.loadFile("fish.wav");
fishSound.setLooping(false);
//background and the fish are from http://morguefile.com/
bg = loadImage("background.jpg");
redFish = loadImage("red.png");
greenFish = loadImage("green.png");
resetIcon = loadImage("reset.png");
size(768, 576);
background(bgColour[0], bgColour[1], bgColour[2]);
ellipseMode(CENTER);
rectMode(CENTER);
imageMode(CENTER);
frameRate(30);
reset();
}
void draw() {
bgSound.play(); //sound didn't work when called in setup
image(bg, width/2, height/2);
for(Agent agent : agents) {
agent.move(light);
agent.draw();
}
light.draw();
image(resetIcon, 20, 20);
}
void mouseClicked() {
if((mouseX > 10) && (mouseX < 30) && (mouseY > 10) && (mouseY < 30)) {
reset();
} else {
int xpos = mouseX + round(random(-2, 2));
int ypos = mouseY + round(random(-2, 2));
if(mouseButton == RIGHT) {
agents.push(new Agent(xpos, ypos, false));
} else {
agents.push(new Agent(xpos, ypos, true));
}
}
}
void mouseMoved() {
light.setPos(mouseX, mouseY);
}
void reset() {
agents = new Array();
}