Every sprite in Fat Gus is drawn by code: how a squirrel is made of ellipses
Fat Gus the Squirrel has ten levels of gardens, fences and rooftops, a fat grey squirrel, cats, dogs, rats, angry neighbours and a different London skyline behind every level. It doesn’t load a single image to show any of it. There are no sprite sheets, no PNGs and no tile sets. Everything on screen is painted by the game’s own code when it starts, and the file that does all of that painting is about 21 kilobytes, smaller than most photos.
That is closer to how a 1980s game worked than how a modern one does. An 8-bit or 16-bit game couldn’t afford to store big pictures either, so artists built graphics out of what the machine could draw quickly. Fat Gus does the same with a handful of drawing tools.
Five tools, all of them square
The art file starts with five small drawing functions, and nearly everything else is built from them:
- R fills a rectangle, rounded to whole pixels.
- ell fills an ellipse, one row of pixels at a time.
- poly fills any straight-sided shape, also row by row.
- line draws a line as a run of little squares.
- dith fills an area with two colours mixed in a checkerboard-like pattern, the trick old games used to fake extra shades.
They all round to whole pixels, and the canvas has smoothing switched off. Nothing is ever drawn at half a pixel, so nothing comes out blurred. The ellipse doesn’t use the browser’s own curve drawing for the same reason: it works out the width of each row itself and fills it as a solid bar, so the edges stay crisp and stepped like real pixel art.
The dithering uses a 4 by 4 pattern of thresholds (an ordered or “Bayer” dither). Each pixel either takes the second colour or doesn’t, depending on its position in the pattern and how much of the second colour is wanted. At level 0.5 you get an even mix. It is how a sky can fade or a shadow can soften without adding a single new colour.
A squirrel is seventeen shapes
Gus himself is drawn by one function, and he is mostly ellipses. In order, back to front:
- The tail, because it sits behind him: a dark ellipse, a body-grey one slightly smaller on top, a light patch for the fur catching the light, and a small red ellipse at the tip.
- Two feet, small dark ellipses whose positions change with the pose.
- The tummy, the biggest ellipse on him, with a cream belly ellipse inside it.
- A red stripe down his back, which is just a rectangle.
- The head, an ellipse with a lighter muzzle.
- The ear, a red triangle with a darker line inside it.
- An eye, a 2 by 2 dark square with a single white pixel for the shine, and a nose, another small square.
- A paw resting on the tummy.
That is the whole squirrel. Drawing back to front means each shape only has to cover what’s behind it, the way a painter works.
Four poses, and a gold one
Gus has four poses: standing, two running frames and jumping. They aren’t separate drawings. The same function draws all four and nudges a few numbers depending on the pose: the feet move to different positions for each running frame, the tail bobs up a pixel or down a pixel, and in the jump everything lifts by two pixels.
Each pose is also drawn a second time in gold. When Gus eats a walnut he glows gold for ten seconds, runs faster and flattens what he lands on, and that glow is the same squirrel painted with three different colours swapped in for his greys. When the walnut is nearly spent, the game flickers between the grey and gold versions as a warning.
All eight versions are painted once, when the game loads, into small 48 by 48 pixel canvases that act like a sprite sheet the game made for itself. After that, drawing Gus each frame is just copying one of those little canvases onto the screen. To face left, the game mirrors the copy instead of keeping a second set of drawings.
The cats, mice, rats, dogs and both kinds of neighbour work the same way, with two animation frames each.
Ten skylines from a few lines each
Each level is a real stretch of London, travelling from Highgate in N6 down to Tooting in SW17, and each one has its own colours and its own landmark on the horizon. The sky is a two-colour band, rows of terraced houses are drawn in a far colour, a line of trees in a nearer one, and then a landmark in silhouette.
The landmarks are tiny drawings in their own right. The view from Hampstead Heath is the Shard, the Gherkin and St Paul’s in the haze: a tall thin triangle, a rounded ellipse on a rectangle, and a dome on a block. The Post Office Tower, Big Ben, the bandstand on Clapham Common and the cinema at Tooting are built the same way. Each is a few rectangles, ellipses and triangles, in one flat colour, which is exactly how distance looks in a 16-bit game.
The colours do quiet work too. The skies get later as you go: bright blue over Highgate, through warmer afternoons in the middle of London, to a deep evening blue over Tooting. It makes the journey home feel like a whole day.
Why bother?
Partly because it’s the point of the site: these are games written the way old games had to be, with the limits that gave them their look. Partly because it’s small and fast. With no images to download, the game is ready almost as soon as the page is, even on a slow phone connection.
And partly because it makes the art easy to change. Making Gus fatter is changing one number, and recolouring a whole level is changing one line.
You can see all of it at work in Fat Gus the Squirrel, and the level guide walks through all ten levels.
How to play, the controls and a guide are on the Fat Gus the Squirrel page.