Skip to content
animorio
IT
Back to the library

Spirograph

SVG, HoverGSAPMediumCompressed weight: Demo 5.0 KBGSAP 28 KBFreeDownload the zip

A minimal spirograph on warm white paper, a single orange ink and hairline strokes: the toothed wheel rolls inside the ring, the pen set in its hole draws the hypotrochoid, the curve closes with a small press and stays in grey under the next figure. The pointer moves the pen hole and the drawing recomputes live; a click swaps the wheel with a clean snap, the tooth counts written small at the bottom.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Spirograph" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Spirograph</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- A minimal spirograph: a wheel rolls inside a ring and the pen draws the curve; the pointer moves the pen hole,
       a click (or a tap) changes the wheel -->
  <main class="stage" data-stage>
    <header class="head">
      <p class="head__name">Spirograph</p>
      <p class="head__hint" data-hint>Move to shift the pen, click to change the wheel</p>
    </header>

    <div class="paper" data-paper>
      <svg class="spiro" data-svg viewBox="-125 -125 250 250" role="img" aria-label="A spirograph drawing a curve">
        <g class="ticks" data-ticks></g>
        <circle class="ring" data-ring cx="0" cy="0" r="100"></circle>
        <g data-ghosts></g>
        <path class="trace" data-trace d=""></path>
        <g class="wheel" data-wheel>
          <circle class="wheel__rim" data-rim cx="0" cy="0" r="40"></circle>
          <line class="wheel__arm" data-arm x1="0" y1="0" x2="20" y2="0"></line>
          <circle class="wheel__hub" cx="0" cy="0" r="1.1"></circle>
        </g>
        <circle class="pen" data-pen cx="0" cy="0" r="2.2"></circle>
      </svg>
    </div>

    <footer class="foot">
      <p class="ratio" aria-live="polite">
        <span class="ratio__mask"><span class="ratio__val" data-ratio>96 / 36</span></span>
        <span class="ratio__label">teeth</span>
      </p>
      <p class="hole">
        <span class="hole__label">pen</span>
        <span class="hole__val" data-hole>0.62</span>
      </p>
    </footer>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

19 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Spirograph” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

At the top the name, Spirograph, and the hint in grey. In the middle a thin ring with ticks, one per tooth (a longer one every eight), and inside it a see-through wheel with its dashed radius out to the pen, a dot with an orange rim. The wheel rolls along the ring and spins on itself, and the pen leaves a thin orange line that grows loop after loop until the figure closes: then the pen gives a small elastic press and the line thins as it settles. After a pause the figure turns grey, the wheel changes size with a small bounce, the tooth counts at the bottom left roll to the new numbers (96 / 36, 105 / 40, 96 / 60, 100 / 35) and the new figure starts over the old ones; two stay in grey. The pointer moves the pen hole: the farther from the centre, the wider the curve; the «pen» number at the bottom right follows it. A click moves on to the next wheel.

How it works

The curve

The wheel centre turns at a distance R − r from the middle, angle t; the wheel spins on itself by −(R − r)/r · t, and the pen sits d · r from its centre. The figure closes after 2π · r / gcd(R, r): that is why the tooth counts are whole numbers.

The growing drawing

A state object carries the progress from 0 to 1 with GSAP (sine.inOut); every frame the SVG path is rebuilt from the points up to the angle reached, every 0.018 radians. So if the pen hole changes, the whole line already drawn is recomputed.

The wheel and the pen

The wheel group moves and turns with a transform computed by hand; the dashed radius runs from the centre to the pen, and the pen dot sits at its tip. Changing wheel only animates the radius shown, with back.out(1.6).

Closing and the old figures

Once the figure closes the pen swells and returns with elastic.out and the line goes from 1.5 times to normal width. Then a copy of the path goes into the group of grey figures, which keeps at most GHOSTS, and the tooth counts roll inside their mask.

The pointer

The pointer’s distance from the ring centre, divided by the ring radius on screen, becomes the pen hole from 0.1 to 0.95; the value chases it by a factor of 0.14 per frame. On phones it works by dragging a finger.

Values to change

NameFileDefaultWhat it changes
RING_TEETHscript.js96The teeth of the outer ring in the first figure.
WHEEL_TEETHscript.js36The teeth of the rolling wheel in the first figure.
PEN_HOLEscript.js0.62Where the pen sits in the wheel, from 0.1 to 0.95.
DRAWscript.js5.6Seconds to draw a whole figure.
HOLDscript.js1.4Seconds of finished figure before the next one.
STROKEscript.js0.55The width of the pen line.
INKscript.js#e0502aThe pen colour.
GHOSTSscript.js2How many old figures stay in grey.

Try them in the Playground

When to use it

For the landing page of a generative art tool or a geometry course, as the background of a portfolio for someone who draws or codes shapes, or for a toy or stationery page: a drawing that makes itself in front of the viewer and answers the pointer.

On phones

The drawing is sized at min(78vmin, 100%), so it fits the box both in width and height; the type uses clamp. On phones the pen hole moves by dragging a finger, and a tap changes the wheel.

With reduced motion

No rolling wheel and no growing line: the figure appears already finished with a fade; a click changes figure with a fade and the pointer moves the pen hole redrawing at once, with no motion on its own.

Pitfalls

  • The tooth counts must be whole numbers: the figure closes after 2π · r / gcd(R, r), and with decimals it never closes.
  • The path is rebuilt every frame: with steps too small (under 0.01 radians) and long figures it gets heavy; 0.018 is enough for a smooth line.
  • The wheel must not leave the ring: r stays at least 4 teeth smaller than R.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 5.0 KB; the libraries: GSAP 28 KB.

Testing

Tested on 2 December 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations