ECHO GARDEN / STUDY / LEVEL 3 OF 7

Grab once,
move every frame.

The controller only reports whether the trigger is down right now. The course framework compares that with the previous frame and turns it into events: press, drag, release, click and double press. Echo Garden decides which note you hold once, at the press, and remembers it until the release. Every frame in between it only decides where the note goes. Compare it with a "magnet" that decides again every frame, as the course's beamSphere.js does.

trigger statedown or up, read every frame
→
eventsdown now and up last frame = press; and so on
→
press: pick a noteheld = nearestSeed(hand), remembered
→
drag: move itno more "is it still under the beam?"

The panel, seen along your beam

the mouse is your beam · hold the button = trigger

Click an empty spot to plant, hold on a note and move to drag it, double-click a note to remove it. While holding a note, use the mouse wheel (or the slider) to move your hand forward and back: the note comes out of the panel by the same amount.

Rules of the grab

empty hand
held note
none
move messages / s
0

Events from the trigger, newest first

From trigger state to events

inputEvents.js

A click is a press and release within 0.5 s with the hand moved less than 3 cm. A double press is two presses within 0.3 s. Drag is called on every frame while the trigger is down. This page runs a copy of these rules.


      

What the scene does with them

echoGarden.js

press stores the note in held[hand] and where the hand and note were. drag moves only held[hand], at most every 0.05 s, and adds the hand's forward movement to the note's depth. release forgets it. pressedSeed stops the click that follows a grab from planting a new note.


      
    

What you should be able to explain

  1. State and events. "The trigger is down" stays true for many frames; "the trigger was just pressed" is true in one frame only. The framework finds it by remembering the last frame: down now and up before = press; up now and down before = release.
  2. Choose at the press, move at every drag. held[hand] is set once. Afterwards a fast swing cannot drop the note, sweeping the beam across other notes picks nothing up, and the scene always knows which id to put in the move message.
  3. Why the magnet fails. It asks "is a note within 8.5 cm of my beam?" in every frame. A slow frame lets the beam jump past the note, and a held trigger picks up every note it sweeps over. Try both with 12 frames per second.
  4. Fewer messages. Drag runs 72 times a second, but a move is sent at most every 0.05 s (20 a second). Moves are absolute positions, so skipping some loses nothing: the next one says where the note is.

Exercises: ① Hold the button on empty space and sweep across the notes, in both modes. ② At 12 frames/s, grab a note and swing quickly: which mode drops it? ③ Why does the scene compare the hand's z to where it was at the press, instead of using the hand's z directly?