Skip to content

Commit 5383be6

Browse files
committed
Update fireflies
1 parent 4caf786 commit 5383be6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

demos/dynamical-systems/firefly-synchronization.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ class FireflySynchronizationDemo extends P5DemoBase {
6666
const panel = this.createControlPanel();
6767

6868
// K slider: 0 = no coupling, high values = strong sync
69-
this.kSlider = this.createSlider(p, 'Coupling (K)', 0, 3, this.K, 0.1, () => {
69+
this.kSlider = this.createSlider(p, `Coupling (K=${this.K.toFixed(1)})`, 0, 5, this.K, 0.1, () => {
7070
this.K = this.kSlider.value() as number;
71-
console.log('K =', this.K);
71+
const sliderParent = this.kSlider.elt.parentElement;
72+
const label = sliderParent?.querySelector('.label');
73+
if (label) label.textContent = `Coupling (K=${this.K.toFixed(1)})`;
7274
});
7375

7476
// Reset button
@@ -233,7 +235,7 @@ export const metadata: DemoMetadata = {
233235
title: 'Firefly Synchronization',
234236
category: 'Dynamical Systems',
235237
description: 'Simulation of fireflies that blink and synchronize via distance-weighted coupling',
236-
instructions: 'Watch the fireflies synchronize. Each firefly starts off with a random frequency near 1hz, and a random phase, and updates its frequency based on how much it differs from the frequencies of other fireflies. Nearby fireflies influence each other more strongly. This uses the <a href="https://en.wikipedia.org/wiki/Kuramoto_model">Kuramoto model</a> for coupled oscillators. '
238+
instructions: 'Watch the fireflies synchronize. Each firefly has a natural uncoupled frequency, randomly assigned between 0.9hz and 1.1hz, and a random starting phase. Then each fly updates its dynamic frequency to try to better match the frequency of the other flies. Nearby fireflies influence each other more strongly, and the overall strength of the matching force is controlled by the parameter K. When K is 0, the flies all act indepenently. When K is high, they synchronize phase and frequency quickly. When K is in the middle, phase may synchronize globally while frequency synchronizes locally. This demo uses the <a href="https://en.wikipedia.org/wiki/Kuramoto_model">Kuramoto model</a> for coupled oscillators. '
237239
};
238240

239241
export default function initFireflySynchronization(

0 commit comments

Comments
 (0)