-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticlesFollowMouse.pde
More file actions
29 lines (25 loc) · 1.21 KB
/
ParticlesFollowMouse.pde
File metadata and controls
29 lines (25 loc) · 1.21 KB
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
// Imports for comparator in AgentController (Used to sort ArrayList by closest agent)
import java.util.Collections;
import java.util.Comparator;
Agent myAgent;
AgentController aController;
ArrayList<Agent> agents;
void setup() {
size(1000, 1000);
int agentAmount = 15; // set the amount of agents/balls
agents = new ArrayList<Agent>();
for (int i = 0; i < agentAmount; i++) { // Create as many agents as previously defined
agents.add(new Agent(i));
}
aController = new AgentController(agentAmount); // Add new controller which handles the connection of agents and mouse (draws a polygon between the mouse and the 2 closest agents)
}
void draw() {
background(0);
for (Agent agent : agents) { // Iterate through every agent of class agents
agent.seek(new PVector(mouseX, mouseY)); // Let them seek the mouse-cursor
agent.update(); // Update position and speed of each agent
agent.edges(); // Check their position regarding the screen-boundaries and spawn them on the opposite site of the screen
agent.show(); // Actual agent rendering/drawing
aController.connect(agents); // Check the distance between agents and mouse-cursor; draw a polygon between the 2 nearest agents and the mouse-cursor
}
}