Grayson’s Song Animation  •  Original Sketch  •  10/18/2026
TNT Processing — p5.js Creative Coding Showcase

Grayson’s Twinkle Animation

400 stars. 400 independent twinkles. One formula.
An animated night sky inspired by “Twinkle, Twinkle, Little Star” — built with sin(), map(), and randomSeed().

⭐  Original Sketch

A Night Sky That Breathes

Grayson animated the classic children’s song “Twinkle, Twinkle, Little Star” entirely from p5.js drawing primitives. The result is a living night sky: 400 stars that twinkle independently, a crescent moon that drifts across the canvas, a central star that rotates, pulses, and cycles through every color of the spectrum, rolling green hills, and the song’s lyrics glowing softly in the foreground.

Unlike Grayson’s earlier bicolor orb, which called noLoop() and drew a single static frame, this sketch is fully animated — draw() runs continuously, updating every element on every frame. The twinkling logic is the pedagogical heart of the piece: a single line of code that makes 400 stars twinkle independently without a single extra variable per star.

p5.js techniques at work: randomSeed() for reproducible star positions • sin(frameCount * 0.05 + ndx) for independent per-star twinkling • map() to convert the sin range [−1, 1] to brightness [30, 100] • push() / pop() with translate(), rotate(), scale() • (starHue + 1) % 360 for cyclic hue cycling • Custom drawStar() via polar-coordinate trigonometry • Crescent moon via overlapping circles
The twinkling logic this sketch teaches: randomSeed(100) resets the random number generator to the same state every frame — so stars never jump to new positions. Then map(sin(frameCount * 0.05 + ndx), -1, 1, 30, 100) oscillates each star’s brightness between dim and bright. The + ndx phase offset ensures every star is at a different point in its cycle — some brightening, some dimming, some mid-glow. One formula. 400 independent lights. See the S.P.A.R.K. Chat Log for the full tutorial.
Ask Copilot Entry #089: Did you notice that the stars always appear in the same positions even though the code calls random()? That is pseudo-random number generation at work. Entry #089 explains exactly how a seeded PRNG produces repeatable sequences, why that is not an oxymoron, and how Java’s Random class does the same thing.

    Live Animation

    Runs continuously — draw() loops at 60 fps.
    Each of the 400 stars twinkles on its own independent cycle.

    By Grayson •  p5.js Sketch •  ~77 lines •  10/16/2026 Original code preserved exactly as written

    What Grayson’s Song Teaches — and the Twinkling Tutorial

    The twinkling logic is the richest teaching moment in Grayson’s sketch. A single expression — map(sin(frameCount * 0.05 + ndx), -1, 1, 30, 100) — solves a surprisingly hard problem: how do you animate 400 objects independently without 400 variables? The answer is phase offsets and the sine wave. The S.P.A.R.K. Chat Log breaks down exactly how it works, examines the commented-out alternative (// let glow = 80;), and teaches the deeper lesson about randomSeed(): stable randomness is not a contradiction.

    Also in the chatlog: the crescent moon cutout technique, the custom drawStar() polar trigonometry, two teachable bugs hiding in plain sight, and a six-direction roadmap for where this sketch could go next.