Skip to content

Commit 866520b

Browse files
committed
Optimized for mobile
1 parent 1c107cd commit 866520b

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

firefly_synchronization/Emit.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ class Emit {
77
}
88

99
update() {
10-
if (!this.finished) {
11-
this.r += emit_speed;
12-
if (this.r > emit_limit) {
13-
this.finished = true;
14-
}
10+
this.r += emit_speed;
11+
if (this.r > emit_limit) {
12+
this.finished = true;
1513
}
1614
}
1715

1816
render() {
19-
if (!this.finished) {
20-
context.strokeStyle = "#ffffff";
21-
context.beginPath();
22-
context.arc(this.firefly.position.x, this.firefly.position.y, this.r, 0, 2 * Math.PI);
23-
context.stroke();
24-
}
17+
context.strokeStyle = "#ffffff";
18+
context.beginPath();
19+
context.arc(this.firefly.position.x, this.firefly.position.y, this.r, 0, 2 * Math.PI);
20+
context.stroke();
2521
}
2622
}

firefly_synchronization/basic.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ function defaultParams() {
6565

6666
if (mobile) {
6767
radius_input.value = 40;
68+
phase_toggle.checked = false;
6869
}
6970
else {
7071
radius_input.value = 70;
72+
phase_toggle.checked = true;
7173
}
7274

7375
noise_input.value = 1;
74-
phase_toggle.checked = true;
76+
77+
7578
}
7679

7780
let click_x, click_y, pressed;

firefly_synchronization/simulation.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let num_fireflies;
44

55
// emit objects
66
let emits = [];
7-
let emit_speed = 0.5, emit_limit = 30;
7+
let emit_speed, emit_limit;
88

99
// synchronization
1010
let sync_strength, sync_radius;
@@ -98,7 +98,9 @@ function render() {
9898
context.fillRect(0, 0, canvas_width, canvas_height);
9999

100100
for (let emit of emits) {
101-
emit.render();
101+
if (!emit.finished) {
102+
emit.render();
103+
}
102104
}
103105

104106
if (phase_toggle.checked) {
@@ -154,18 +156,30 @@ function initParams() {
154156
if (mobile) {
155157
firefly_radius = 3;
156158
repulsion_radius = 9;
159+
160+
emit_speed = 0.75;
161+
emit_limit = 15;
157162
}
158163
else {
159164
firefly_radius = 5;
160165
repulsion_radius = 15;
166+
167+
emit_speed = 0.5;
168+
emit_limit = 30;
161169
}
162170

163171
frame = 0;
164172
fireflies = [];
165173
emits = [];
166174

167175
num_fireflies = 0;
168-
addFireflies(100);
176+
177+
if (mobile) {
178+
addFireflies(70);
179+
}
180+
else {
181+
addFireflies(100);
182+
}
169183

170184
updateParams("num");
171185
updateParams("strength");

firefly_synchronization/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ function removeFinishedEmits() {
1919
}
2020

2121
function getFirefliesWithin(firefly, radius) {
22-
let repelling_fireflies = [];
22+
let fireflies_within = [];
2323
for (let other_firefly of fireflies) {
24-
if (firefly !== other_firefly) {
24+
if (firefly != other_firefly) {
2525
if (distanceBetween(firefly.position, other_firefly.position) < radius) {
26-
repelling_fireflies.push(other_firefly);
26+
fireflies_within.push(other_firefly);
2727
}
2828
}
2929
}
30-
return repelling_fireflies;
30+
return fireflies_within;
3131
}
3232

3333
function addFireflies(number) {

gifs/firefly_sync.gif

2.18 MB
Loading

0 commit comments

Comments
 (0)