Grayson’s Song  •  Stage 2 & Cross Training  •  10/19/2026
TNT — Creative Coding & Cross Training

Grayson’s Twinkling Stars — Professional Edition

A professionally organized p5.js animation of “Twinkle, Twinkle, Little Star.”
The source sketch for the three-language App Comparison — named constants, modular scene functions, and JSDoc documentation that make the code readable in any Processing dialect.

✨  Cross Training — Professional Edition

Five Goals Every Developer Should Have

This p5.js sketch animates “Twinkle, Twinkle, Little Star”: 400 independently twinkling stars against a deep night sky, a crescent moon drifting across the canvas, a central five-pointed star that rotates, pulses in size, and cycles through every color of the spectrum, rolling green hills, and the song’s first couplet glowing in the foreground.

The version you see here is professionally organized — every bare number replaced with a descriptive name, every visual element extracted into its own function, and every function documented with a comment block explaining what it does and why it works that way. These five practices are not style preferences: they are the habits that make code easy to read, easy to change, and easy to translate. When every value is named and every layer is a function, seeing what changes between JavaScript, Java, and Python — and what stays exactly the same — becomes immediately clear. That is why this version is the foundation of the App Comparison.

  • 1
    Name Your Constants. Replace every bare number with a descriptive const. TWINKLE_SPEED = 0.05 explains itself; bare 0.05 does not. Anyone reading the code — including you, three months from now — immediately knows what to change to make the stars twinkle faster or slower.
  • 2
    One Function, One Job. draw() is now a six-line scene recipe. Each scene element (drawStars(), drawMoon(), etc.) lives in its own function. You can comment out drawMoon() and the moon disappears without touching any other code. That is testability in its simplest form.
  • 3
    Separate Constants From State. Constants (values that never change) and state variables (values that change every frame) are in clearly labeled sections. CW = 400 never changes. moonX changes 60 times per second. Keeping them separate makes both easier to reason about.
  • 4
    Document Every Function. A brief JSDoc block above each function answers: What does this do? and Why does it do it this way? The drawStars() comment explains the randomSeed() trick and the phase-offset technique — two ideas that are invisible without documentation.
  • 5
    Fix Your Bugs First. The typo "twinle" is corrected. The undeclared ndx in drawStar() is declared. The leftover comments are removed. These are small fixes — until the code grows, and they become invisible landmines. Make clean code a habit, not a cleanup task.
This is the Cross Training source sketch. The App Comparison page shows this code side by side with its Java Processing and Python Processing translations — the same named constants and the same modular structure expressed in each language’s own syntax.

    Live Animation — Stage 2

    Twinkle, Twinkle, Little Star — 400 independent twinkles,
    a drifting crescent moon, and a color-cycling central star.

    Original by Grayson •  Stage 2 refactoring by TNT •  p5.js •  ~220 lines including documentation p5.js source for the JS / Java / Python App Comparison