Twinkling Stars  •  Hue Drift Edition  •  09/30/2026
TNT — p5.js Creative Coding & Cross Training

👻 ✨ Henry’s Ghost Saga:
Twinkling Stars with Hue Drift

An extension of the original twinkling stars: all stars now slowly cycle through the color wheel together. Three new ideas — float accumulator, loop scope rule, and saturation floor — each small, each important.
Born from a Java offroading trip that found three bugs. See the Chat Log for the full story.

✨  Extension: Hue Drift Added

Three New Ideas on Top of the Original Sketch

The original Twinkling Stars sketch fixed the hue at yellow (60° on the HSB wheel). This version adds a continuous hue drift: a globalHue float accumulator advances 0.3° per frame, cycling all stars through the full color wheel together every ∼40 seconds. Twinkling is still click-toggled independently.

Three small but significant changes make it work correctly:

  • Float accumulator: globalHue += HUE_SPEED (fixed step) instead of frameCount × factor (grows over time).
  • Outside the loop: Hue advances once per frame, before the star loop. Inside the loop: every star gets a different hue that frame — a rainbow, not a drift.
  • Saturation floor at 20: Stars with saturation near 0 are nearly gray; they can’t show a hue change. A floor of 20 ensures every star participates.
Origin: These lessons emerged from a Java offroading session that produced three bugs. The fix became the sketch; the bugs became a lesson. Read the full story in the S.P.A.R.K. Chat Log.

    Live sketch requires a larger screen.
    Try rotating to landscape.

    Live Sketch

    Stars drift slowly through the color wheel.
    Click the canvas to toggle twinkling on/off.

    What Changed from Twinkling Stars v1

    Every concept from the original sketch carries over unchanged: HSB color mode, sinusoidal twinkling, phase offsets, the Processing lifecycle, named constants, and the click-to-toggle handler. Only three things are new:

    • Removed: var STAR_HUE = 60 (fixed constant)
    • Added: var HUE_SPEED = 0.3 and var globalHue = 60 (float accumulator)
    • Changed: first line of draw() now updates globalHue and computes starHue before the star loop
    • Changed: saturation range from random(0, 100) to random(20, 100)
    • Inside the loop: star.h = starHue — replaces the fixed star.h set only in setup()

    App Comparison (JS / Java / Python)  •  Chat Log — Java bugs & class design

    Download source twinklingStarsWithHueSketch.js twinklingStarsWithHue.py TwinkeAndChangeHueJavaSketch.pde