Eye 6 makes the pupils interactive: click and drag either pupil
to reposition it inside the sclera. The two glints follow automatically,
preserving their fixed offsets from the pupil center. This stage introduces
the drag pattern that all later stages build on.
Big Idea 1 — setDraggable(true) Opts a Point In
Calling leftPupilCenter.setDraggable(true) marks the SWPoint
as interactive. The sketch’s mousePressed() then uses
containsPoint(mx, my, grid, 10) to check whether the click lands
within 10 pixels of that point — and only then begins a drag. This opt-in
approach keeps non-interactive points completely unaffected.
Big Idea 2 — draggedPoint: One Variable Drives the Loop
A single sketch-level variable draggedPoint holds a reference to
whichever SWPoint is being dragged (or null when nothing
is moving). Every call to mouseDragged() checks this one variable;
if it’s non-null, the point is repositioned. This “one dragged thing at a
time” pattern is a simple, readable way to manage interactive state.
Big Idea 3 — Glints as Dependents with Fixed Offsets
Each pupil stores its glint offsets (glintTopOffsetX/Y,
glintBottomOffsetX/Y) at setup time. During dragging,
mouseDragged() uses those stored offsets to call
setPosition() on both glint centers, keeping them locked at the
same relative position to the pupil. No re-computation of polar coordinates
is needed — the offsets were already computed once in Cartesian form.
Big Idea 4 — Click-Through: Grid Toggle Survives Drag Mode
If the user clicks somewhere that is not a draggable pupil,
mousePressed() falls through to the default action: toggling
the grid. The return statement after each successful drag-start
prevents the grid from inadvertently toggling every time a pupil is grabbed.
This “early return” pattern makes the event priority chain explicit and readable.