CC 3D Starfield

Version 1.0 — © 1996 Christian Cohnen

The 3D starfield is probably the oldest trick in the demoscene book. Every home computer from the C64 to the Amiga had one, and it was often the very first effect a budding demo coder would attempt — on the Atari ST it was practically a must-have, appearing in almost every demo and intro from the late 1980s onward. The idea is dead simple: scatter points in 3D space, project them onto the screen with perspective division, and scroll the Z axis to fly through them.

This version adds a twist — literally: the entire star field rotates around the view axis using a sine/cosine rotation, so instead of just flying straight ahead you spiral through the stars. Four different star sprites (from large and bright to small and dim) are selected based on depth, giving a convincing sense of distance without any actual lighting calculation. The coordinate space wraps around using bitwise masking, so the field is effectively infinite — stars that fly past the camera reappear in front. The flight direction drifts automatically, slowly changing between forward, left, right and center, giving the effect a life of its own even without interaction.

Keyboard controls let you steer in all directions and change the rotation speed, turning the starfield into a tiny interactive flight simulator.

Originally a Java applet (1996). The original Java applet code was transpiled to JavaScript/Canvas in 2026 so the effect can run in modern browsers without a Java plugin. The JavaScript version calculates the star sprites procedurally using radial gradients at startup instead of loading external GIF images — this produces cleaner anti-aliased results without depending on any image files. Rendering uses 2×2 pixel doubling for an oldschool chunky look true to the era.

Features

Applet Parameters

NameTypeDescriptionDefaultRequired
starsintNumber of stars to render60no

Parameters (STARFIELD_CFG)

NameTypeDescriptionDefault
starsintNumber of stars to render60
rotSpeedintBase rotation speed2
pixelScaleintPixel size multiplier (2 = chunky retro look)2

Keyboard Controls

KeyAction
/ 8Fly backward (decrease Z speed)
/ 2Fly forward (increase Z speed)
/ 4Strafe left
/ 6Strafe right
PgUp / 7Move up
PgDn / 1Move down
9Rotate counter-clockwise
3Rotate clockwise
5Center (stop horizontal/vertical drift)

Mouse Interaction

Moving the mouse (or touching) over the canvas influences the rotation direction. Moving the cursor to the left rotates counter-clockwise, moving it to the right rotates clockwise. The effect smoothly blends with the base rotation and decays when the cursor leaves the canvas.

Applet Code Example

<applet archive="Starfield.jar"
  code="ccStarfield.class" width="300" height="300">
  <param name="stars" value="80">
</applet>

JavaScript Canvas Version

<canvas id="game" width="300" height="300"></canvas>
<script>var STARFIELD_CFG = { stars: 80 };</script>
<script src="starfield.min.js"></script>