...loading...
Canvas size:
Grid:
Now! ~ the SWEyeball Class (with pupil constraints)! - Stage
...loading...
Canvas size:
Grid:
SWEyeball: Complexity in a Class
Eye 7 is the big leap: everything built piece by piece across stages 1–6 is now
encapsulated inside a single SWEyeball class.
The sketch drops from 14+ individual variables down to two —
leftEye and rightEye — and the entire drag system
disappears from the sketch entirely.
Big Idea 1 — One Constructor Call Replaces 14 Variables
In Eye 6, each eye required seven SWPoint and SWDisk
objects plus a drag-dependents struct. SWEyeball takes seven
parameters and builds all of that internally. The sketch no longer knows or
cares about leftEyeBase, leftPupilCenter,
leftTopGlintCenter, etc. — they are private details hidden
inside _buildComponents().
Big Idea 2 — drawOnGrid(): 8 Calls Become 2
Eye 6’s draw() made eight individual drawOnGrid()
calls and had to get the order right (sclera → pupil → top glint →
bottom glint). SWEyeball.drawOnGrid() encodes that order once,
permanently. Eye 7’s draw() is just:
leftEye.drawOnGrid(grid);
rightEye.drawOnGrid(grid);
Big Idea 3 — The handle* Event-Delegation Pattern
All drag state (draggedPoint, leftDragDependents,
rightDragDependents) that lived in the sketch in Eye 6 is now
private to each SWEyeball instance. The sketch simply delegates:
if (leftEye.handleMousePressed(mouseX, mouseY, grid)) return;
if (rightEye.handleMousePressed(mouseX, mouseY, grid)) return;
handleMousePressed() returns true if it consumed the
event, letting the sketch skip its own logic. This boolean-return delegation
pattern is the same convention used in Bootstrap components and Android
event listeners.
Big Idea 4 — Encapsulation Is the Point
The sketch went from a page of setup code to a handful of constructor calls. From eight draw calls to two. From a sprawling event handler to three one-liners. The behavior is identical — the complexity didn’t disappear, it moved to where it belongs: inside the class that owns it.