-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathFlockingArrows.pde
More file actions
103 lines (90 loc) · 2.32 KB
/
FlockingArrows.pde
File metadata and controls
103 lines (90 loc) · 2.32 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Flocking Arrows
*
* A generative art application featuring flocking arrows that follow
* the Boids algorithm (separation, alignment, cohesion).
*
* CONTROLS:
* - Move mouse to interact with arrows (they will avoid the cursor)
* - Click mouse to attract arrows
* - Press SPACE to add more arrows
* - Press 'r' to reset
* - Press 's' to save screenshot
*/
ArrayList<Arrow> flock;
boolean mouseAttract = false;
void setup() {
size(1200, 800);
smooth();
// Initialize flock
flock = new ArrayList<Arrow>();
for (int i = 0; i < 100; i++) {
flock.add(new Arrow(random(width), random(height)));
}
}
void draw() {
// Create trailing effect
fill(10, 10, 15, 30);
noStroke();
rect(0, 0, width, height);
// Mouse interaction
PVector mousePos = new PVector(mouseX, mouseY);
// Update and display all arrows
for (Arrow arrow : flock) {
arrow.run(flock);
// Mouse interaction
if (mousePressed) {
// Left click: attract
if (mouseButton == LEFT) {
PVector attraction = arrow.seek(mousePos);
attraction.mult(0.5);
arrow.applyForce(attraction);
}
// Right click: repel
else if (mouseButton == RIGHT) {
PVector flee = arrow.flee(mousePos);
flee.mult(2.0);
arrow.applyForce(flee);
}
} else {
// Default: arrows avoid cursor when not clicking
PVector flee = arrow.flee(mousePos);
flee.mult(1.0);
arrow.applyForce(flee);
}
}
// Display info
displayInfo();
}
void displayInfo() {
fill(255, 200);
textAlign(LEFT);
textSize(12);
text("Arrows: " + flock.size(), 10, 20);
text("FPS: " + int(frameRate), 10, 35);
text("Mouse: Avoid | Left Click: Attract | Right Click: Repel", 10, height - 10);
text("SPACE: Add arrows | R: Reset | S: Save", 10, height - 25);
}
void keyPressed() {
// Add more arrows
if (key == ' ') {
for (int i = 0; i < 10; i++) {
flock.add(new Arrow(random(width), random(height)));
}
}
// Reset
if (key == 'r' || key == 'R') {
flock.clear();
for (int i = 0; i < 100; i++) {
flock.add(new Arrow(random(width), random(height)));
}
}
// Save screenshot
if (key == 's' || key == 'S') {
saveFrame("flocking-arrows-####.png");
println("Screenshot saved!");
}
}
void mousePressed() {
// Could add more interaction here
}