Visualizations
489 / 500

489 · 3D

Sundial Garden

A pastel garden lit by the real sun, with shadow-mapped shadows and a working sundial.

The sun's altitude and azimuth come from the textbook formulas: declination from the day of the year, the hour angle from local solar time (the clock plus the equation of time, which is why the dial and the clock disagree by up to 16 minutes) and the latitude. A small software rasterizer draws the flat shaded diorama with a z-buffer, near plane clipping and per-row spans, and renders two orthographic shadow maps from the sun every frame, a coarse one over the garden and a fine cascade over the dial, which each pixel samples with bilinear percentage closer filtering. The sundial is a true horizontal dial for the chosen latitude: its gnomon points at the celestial pole and every hour line is the shadow of that edge at a whole hour of solar time, so the close-up shows it telling the right time all year. Sky light is a hemisphere term that turns from noon blue to sunset gold, and after dark the windows and the lantern take over.

Try it. Drag the time, date and latitude sliders to see summer and winter, the tropics and the far south. Drag the scene (or use the arrow keys) to orbit, walk with WASD, press space to pause or play time, and [ or ] to nudge it by a quarter hour.

  • Solar position
  • Shadow mapping
  • Percentage closer filtering
  • Software rasterizer
  • Hemisphere lighting
  • Sundial geometry

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a tiny low-poly garden with a working sundial, lit by the real sun, using JavaScript and the HTML canvas element. Write the 3D rendering yourself with the 2D canvas (no WebGL, no libraries) and put everything in a single index.html file I can open directly in a browser.

Start simple:
- Model the scene as a list of triangles, each with a flat color: a square lawn, a few boxes for a house and hedges, cone trees, and a round pillar with a flat dial plate in the middle.
- Compute the sun's direction from latitude, day of the year and clock time: the declination is about -23.44 degrees times cos(2 pi (day + 10) / 365), the hour angle is 15 degrees per hour from solar noon, and the standard formulas turn those into altitude and azimuth.
- Orbit a camera around the garden, project the triangles in perspective, sort them far to near (painter's algorithm) and fill them with the canvas path API, shading each by an ambient sky term plus the sun times the dot product of its normal and the sun direction.
- Add sliders for time of day, date and latitude, and let time advance on its own.

Once that works, make it beautiful:
- Add a gnomon tilted to your latitude so its edge points at the celestial pole, and draw hour lines on the plate at angle atan(sin(latitude) tan(15 degrees times the hours from noon)).
- Cast shadows by projecting each object's vertices along the sun direction onto the ground and filling the convex hull in a translucent dark color, so the gnomon's shadow sweeps across the hour lines.
- Pick a pastel palette and change the sky and light color with the sun's height: warm and low at sunset, deep blue at night with lit windows.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a real z-buffer rasterizer with shadow maps, the equation of time, or a close-up view of the dial.
PreviousTiny CompilerA whole compiler, from source to running bytecode, rebuilt on every keystroke. NextDissonance CurvePlomp-Levelt roughness summed over every partial pair: where consonance comes from.

Related visualizations

  • AnalemmaAstronomy A garden noon mark traces the figure eight of Earth's orbit, one stud a day.
  • Shadow Sculpture3D One carved object casts three different shadows at once. Draw your own.
  • Zen GardenGenerative art Raked gravel in low morning sun, its furrows flowing around mossy stones.
  • TotalityAstronomy A total solar eclipse from a lakeshore, driven by the real shadow geometry.
  • Sky MachinePhysics Drag the sun and watch real Rayleigh and Mie scattering paint the sky.
  • Checker ShadowIllusions Squares A and B are the exact same gray. Move the light and the shadow keeps lying.
  • Voxel Diorama3D A floating voxel island with baked AO, sun shadows and a waterfall. Click to build.
  • Bloom3D Procedural flowers open from bud to bloom, with ruffled, translucent, veined petals.
  • Engraving Renderer3D A moving 3D still life printed as a copperplate engraving, line by swelling line.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs