ECHO GARDEN / STUDY / LEVEL 4 OF 7

Who sings
with whom.

Two notes closer than 37 cm are linked by a strand, and every link becomes part of the melody. A link between two players' notes is a duet. Links are never sent over the network: every headset computes them from the garden with the same function, gardenLinks, so both players see the same strands. This page runs it.

every paircloser than 0.37 m, measured in 3D
→
sortduets first, then the closest pairs
→
one partner eachtake a pair only if neither note is taken
→
same order everywheresorted by id, so every headset agrees

The panel

drag notes · the selected note can be pulled out
duet (two players)solo link (one player)circle: 37 cm around the selected note

The links

Every candidate pair, in the order gardenLinks considers them

pairdistancekindresult

The real code

echoGardenRules.js

Two loops make every pair once (j starts after i). The pairs are sorted, then taken greedily: a pair is kept only if neither note is already used. The final sort by id gives every headset the same order, which level 6 uses to agree on the beat.


      

Where the scene draws them

echoGarden.js

Each link gets a strand, kept in a map by the link's id. A link that was not there in the last frame plays both notes once: that is how you hear two notes "meet".


      
    

What you should be able to explain

  1. Derived, not sent. The links depend only on the notes. Both headsets have the same notes (level 7), so they compute the same links without a single extra message. Sending links too would only make it possible for them to disagree.
  2. Greedy pairing. Sorting by distance and taking a pair only when both notes are free gives each note at most one partner. A crowd of notes still makes a readable set of strands and a clear melody.
  3. Duets first. When a note could pair with its own player's note or with the other player's, the duet wins. The rule pushes the two players to compose together.
  4. Deterministic order. Object.entries can list notes in a different order on different headsets. Ties are broken by id and the result is sorted by id, so the answer never depends on that order.

Exercises: ① Put three notes close together. Which two are linked, and why is the third left alone? ② Untick "duets first" and find an arrangement where the links change. ③ Pull the selected note out of the panel: why can two notes that overlap on the screen be unlinked?