Stage 6 adds SWGhost.stretching(sinusoid, t) — a sinusoid-driven
vertical stretch that makes the ghost grow and shrink rhythmically. It is the ghost-level
analogue of SWRectangle.breathe(), but operates on the composite
silhouette rather than a single shape's vertices. All Stage 5 features (sinusoid
hover, Perlin-noise eye wander, Follow/Track, full Control Panel) are preserved.
Big Idea 1 — How stretching() Works
Every ghost stores a rest height _baseBodyHeight (copied from the
constructor argument). Each frame, stretching(sinusoid, t) computes:
bodyHeight = _baseBodyHeight + sinusoid.getValue(t)
It then calls _build() to reconstruct all child parts using the new
height. The head anchor stays fixed; the body rectangle gets taller or shorter and
the toe disks shift down with it. Setting sinusoid.C = 0 gives a
symmetric oscillation centered on the rest height. Increasing A widens
the stretch range; increasing the period slows the breathing tempo.
Big Idea 2 — Composing Three Concurrent Animations
Hover, stretch, and eye wander are fully independent and can all run simultaneously.
The order in draw() matters:
- Hover (
setPosition) — repositions the head anchor and calls _build() with the current bodyHeight.
- Stretch (
stretching) — updates bodyHeight and calls _build() again with the new height and the already-updated position.
- Eyes —
lookingAround() or lookAt() updates pupil offsets; no rebuild needed.
The two _build() calls per frame (one from hover, one from stretch) are
cheap — they create a handful of plain objects. Eye noise state is preserved
across both rebuilds via the save/restore logic introduced in Stage 5, so the wander
continues without interruption.
Big Idea 3 — Incommensurable Periods (Three Sinusoids)
The defaults — H period 5 s, V period 3 s, S period 2.5 s —
share no common factor below their LCM (15 s), so the combined motion never
visibly repeats within a typical viewing session. Setting all three to the same value
produces a rigidly synchronized bounce-and-stretch. Setting S to exactly double the V
period means the ghost is fully extended every other bob — a satisfying way to
see the phase relationship directly.
Big Idea 4 — Control Panel Parameters
| Control |
What it changes |
Range / default |
| Follow / Track / Look Strength / Noise Speed / Iris Color / Iris Width | Eye animation (inherited from Stage 5) | same as Stage 5 |
| Animate (SPACE) | Toggle sinusoid hover on/off | ON / OFF |
| H / V Amplitude | Hover drift in user units | 0–1.5, defaults 0.20 / 0.30 |
| H / V Period | Hover cycle length | 1–15 s, defaults 5 / 3 |
| Stretch (S key) | Toggle sinusoid vertical stretch on/off | ON / OFF |
| S Amplitude | How much the ghost grows/shrinks from rest height (user units) | 0–2.0, default 0.50 |
| S Period | Stretch cycle length | 0.5–10 s, default 2.5 |
| Ghost Color / Num Toes / BG Color / BG Opacity | Visual options (inherited from Stage 5) | same as Stage 5 |