Apfelsee & Fraktsee

Analysis of three C64 programs that turn the Mandelbrot set into a landscape: Fraktal-Landschaft (Happy Computer 6/87), Apfelsee (64'er Sonderheft 33) and Fraktsee (64'er Sonderheft 57).

The Apfelsee as a C64 multicolour landscape: blue lake between green, white-lit shores
View across the Apfelsee: position X 0, Y −1.2, eye height 4, view 0°. Computed with the original algorithm, upper sky cropped.

Introduction

From 1987 onwards, German computer magazines published three C64 programs that show the “Apfelmännchen” (Mandelbrot set) not as a flat colour image but as a landscape you can walk through: a lake lies where the iteration does not escape, and land rises in steps all around it. The viewer chooses position, eye height and viewing direction, and the C64 turns this into a perspective picture over several hours.

This analysis examines the three programs – “Fraktal-Landschaft” from Happy Computer 6/87, “Apfelsee” from 64'er Sonderheft 33 and “Fraktsee” from 64'er Sonderheft 57 – at code level. It explains how landscape, perspective, colouring and the impression of light are created, how the programs are structured and how they are related.

The result up front: these are not three separate developments but one program in three guises. Apfelsee and Fraktsee take over the formula, constants and machine code of the Happy listing unchanged; they differ in operation and speed, not in the picture.

Summary

All three programs compute the same picture with the same algorithm and the same graphics routines. Their origin is the BASIC listing “Fraktal-Landschaft” by Frank Göldner and Hartmut Woerrlein from Happy Computer 6/87.

Sources

The table shows the material on which the analysis is based: the three magazine articles with their listings and the disk images on which the programs survive. Fraktsee exists as a file, Apfelsee only as a printed hex listing.

Source Content
Happy Computer 6/87, pp. 19–27 Article and BASIC listing “Fraktal-Landschaft” (C64, CPC, Atari ST/XL, Amiga)
64'er Sonderheft 33, pp. 18–25 Article “Apfelsee”, MSE listings APFELSEE, F1 C000, AUFSICHT PACKED
64'er Sonderheft 57, p. 11 Article “Fraktsee”, “Fahrplan” table of locations, Fraktlader
fraktsee.prg, sb010057.d64, sb066694.d64 Fraktsee, three byte-identical copies
sb066246.d64 (Crackpot Games) “APFELSEE – HAPPY” (Woerrlein variant with clouds), MSE V1.0

Family Tree of the Programs

Happy Computer 6/87Fraktal-Landschaft: BASIC + 304 bytes MLFrank Göldner, Hartmut Woerrlein64'er SH 33: Apfelseehand-translated into 6502 codegraphics routines byte-identical+ menu, map, 4 MHz modeDavid MehlhausenCrackpot disk»APFELSEE – HAPPY«Woerrlein variantmenu, cloudy skyML part missing on diskCompiled »THC 3001«BASIC compiler, 2 packerstitle: Fractal CalculateML byte-identical(c) 1987 Markt & Technik64'er SH 57: FraktseeEnglish user interfaceauthor per issue: Frank Michliktranslated by handextendedcompiledon the issue disk
Figure 1: Origin of the programs, established by byte comparison and program texts.

The Happy listing is the common source. Apfelsee and Fraktsee both take over its machine code unchanged; only the BASIC part was translated, by hand (Apfelsee) or by a compiler (Fraktsee).

Program Flow

All three programs go through the same stages; the differences lie in start-up, choice of position and operation, shown on the right in the grey boxes.

Start the programput the code in placeHappy: poke DATA lines to $C000Apfelsee: code to $6000, load F1Fraktsee: unpack twice, RUNMenu (Apfelsee only)View, Load, Save, New pictureChoose positioncoordinates X and YHappy, Fraktsee: number inputApfelsee: crosshair on map AUFSICHTCompute terrain heightiteration at the position, displayApfelsee: Z from 200 in steps of 5Enter eye heightHH above terrain?noyesEnter viewing angleKU in degreesHappy, Fraktsee: 0° = 2nd coordinateApfelsee: 0° = top edge of mapCompute and draw picturegraphics on, 300 rows × 161 columnssee flow per pixelApfelsee: interrupt throttled,SHIFT LOCK blanks the screen,abort with the ← keyPicture finishedHappy, Fraktsee: picture staysApfelsee: back to the menu (dashed)
Figure 2: Program flow from start to finished picture, from listings and disassembly.

The only loop back in the common flow is the height check: if the eye is below the terrain, input starts again. Only Apfelsee returns to the menu after the picture.

The Common Algorithm

The picture is created much like ray tracing: every pixel is traced back to a point on the number plane, the height is determined there and drawn as a vertical stick. All three programs perform exactly these steps; the following formulas come from Happy lines 80–272 and can be found operation by operation in Apfelsee ($C1B0–$C6DA).

Row V1, 3 … 599E = 10·H/VColumn HO−80 … 80HC = 0.0187·E·HOPlane pointrotation by KUgives XC, YCIteration|x|−|y|−XC, 2xy−YCmax. 41 steps, ZSmoothingZ = 0.7·ZA + 0.3·ZZA = left neighbourLake testZ below 0: lake, blueelse land, greenScreen heightC = (Z−H)·V/Hclamped to ±98Draw stickdouble column, pixel,shadow linenext HOAfter HO = 80 comes the next row V; after V = 599 the picture is finished.
Figure 3: Flow per pixel: Happy lines 80–272, Apfelsee $C2F3–$C6DA.

The expensive step is the iteration: up to 41 passes with one multiplication and five additions each per pixel.

1. Input and Height of the Position

The user enters the position (X1, Y1), eye height H and viewing angle KU. First the terrain height at the position is computed; if H is below it, the input is rejected.

2. Loops and Projection

The outer loop runs V = 1, 3, 5 … 599 (300 rows), the inner loop HO = −80 … 80 (161 columns). From these follow the distance E, the lateral offset HC and the point (XC, YC) on the plane:

E = 10·H / V HC = 0.0187 · E · HO
XC = X1 + HC·cos KU + E·sin KU YC = Y1 − HC·sin KU + E·cos KU

E = 10H/V is exactly the distance at which a line of sight through screen row 98 + V hits the plane Z = 0. Distant points therefore come first, near ones last.

3. The “Fractal Iteration”

The start values are XA = YA = 0 and Z = 2. Per step:

x ← |x| − |y| − XC y ← 2·x·y − YC Z ← Z − 0.05

The iteration stops when |x| + |y| > 400 or Z becomes negative. Z = 2 − 0.05·n is therefore the height: points that escape quickly lie high; points that never escape form the lake.

Height field of the lake formula
Figure 10: The lake is a compact area around the origin with a long, narrow channel along the first coordinate. Around it the land rises in steps of 0.05 up to about 1.75. The red frame shows the area covered by the Apfelsee map.

The formula is not a Mandelbrot iteration. The true Mandelbrot set would have x² − y² in the real part; here there are absolute values. The minus sign before XC also mirrors the figure. All ports in the Happy issue (CPC, Atari ST, Atari XL, Amiga) use the same variant, as does Apfelsee.

True Mandelbrot set next to the lake formula
Figure 11: Left the true Mandelbrot set, right the lake formula of the three programs, both computed with the same bailout rule and mirroring. The colour shows after how many steps a point escapes; C64 blue is the lake. Instead of round buds, the Apfelsee has frayed shores and a long channel to the right.

4. Smoothing, Lake and Screen Height

Z = 0.7·ZA + 0.3·Z C = (Z − H)·V / H, |C| ≤ 98

ZA is the value of the neighbouring pixel to the left. If the smoothed Z is negative, the point becomes lake (colour 0, Z = −0.0001). C is the height on screen relative to horizon row 98.

The rounding quirk. With exact arithmetic, Z would be exactly 0 after 40 steps and the raw lake value only a tiny minus. The smoothing would then have kept every lake point to the right of land positive for about 100 pixels, and lakes would be smeared to the right. The C64 format, however, rounds 0.05 slightly up and rounds every subtraction; by my calculation about +3 × 10⁻⁹ remains after 40 steps. Only step 41 stops, with Z = −0.05, and that is enough to tip below zero after a few pixels. The sharp shores of the original pictures therefore depend on this effect. Apfelsee behaves the same, because it uses the same ROM routines and the same constant 0.05.

5. Stick Technique

Up to four graphics commands are executed per pixel:

  1. Double column: column 81 + HO white and column 80 + HO light blue, each from row 98 − C to the bottom edge.
  2. If C < 0, a pixel in surface colour at row 99 − C.
  3. If C > CA + 0.2 (a steep step compared with the predecessor), a blue shadow line from 99 − C to 99 − CA.
  4. The surface pixel at row 98 − C in surface colour (green for land, blue for lake).

Because the rows run from far to near, each new row paints over most of the sticks before it. Only the top edge remains visible – that is the surface. The 600 instead of 200 rows are the “dead angle” from the Apfelsee article: high points close in front of the viewer still cover parts of the picture drawn earlier.

Drawing Only

Input per pixelHO, height C, predecessor CA, colour FADouble column ($C0E9)column 81+HO white: 98−C to 199column 80+HO light blue: 98−C to 200C < 0?yesnoPixel below the edge(80+HO, 99−C) in colour FAC > CA + 0.2?yesnoShadow line ($C0D8)column 80+HO, 99−C to 99−CA, blueSurface pixel(80+HO, 98−C) in colour FARemember: CA = Ccontinue with the next HOSubroutine set pixel ($C068)Byte address$2000 + (y div 8)·320+ (x div 4)·8 + (y mod 8)Choose bit pairposition 3 − (x mod 4) in the bytemasks $3F, $CF, $F3, $FCWrite bytebyte AND mask OR colourcolour 0–3 uses 2 bitsLine ($C0DB)set pixel, y + 1,until y equals end rowAll drawing commands on the left use this routine.
Figure 4: Drawing one pixel: Happy lines 261–265, machine code $C068–$C129.

Drawing knows only pixels and vertical lines. Every pixel costs an address calculation with up to 24 additions of 320 (one per character row), because the 6502 cannot multiply; a full double column consists of up to 200 such pixels.

Graphics, Colours and Memory

All three programs draw in multicolour bitmap mode (160 × 200 pixels) with the bitmap at $2000 and the same four colours. The graphics routines come from Happy and are called via SYS with parameters (Happy, Fraktsee) or called directly (Apfelsee).

Bit pattern Colour source C64 colour Meaning in the picture
%00 $D021 = 6 blue sky, lake, shadow line
%01 screen RAM, upper nibble 3 light blue left stick column
%10 screen RAM, lower nibble 1 white right stick column (light from the right)
%11 colour RAM = 5 green land surface
Address Happy call Function
$C000 (49152) SYS XQ graphics on, set colours, clear bitmap
$C059 (49241) SYS XW,x,y,f set one multicolour pixel
$C0D8 (49368) SYS 49368,x,y1,y2,f vertical line from y1 down to y2
$C0E9 (49385) SYS 49385,x,y1,y2,f stick: column x in colour f, column x−1 in colour f−1 down to y2+1

The line routine counts Y up with INC until Y = y2; with y1 > y2 it wraps past 255. The BASIC logic only calls it with y1 < y2. The stick of column HO = 80 lands at x = 161; the address calculation puts this pixel into the next character row on the far left. That is where the thin light stroke at the left edge during picture build-up comes from.

Memory map. Happy and Fraktsee occupy $0801 upwards with the (compiled) BASIC program, $C000–$C12F with the graphics routines, $0400 and $D800 with the colours and $2000–$3FFF with the bitmap. Apfelsee moves its main program to $6000–$67E6 at start and loads the computing routines F1 to $C000–$C6DF; the variables are 5-byte floating-point numbers at $67EB–$685E and $C6DF–$C7B5. Saved pictures contain only the bitmap $2000–$3FFF; each program sets the colours anew when displaying. That is why the Fraktsee article needs the “Fraktlader”, which fills colour memory with 81 ($51) and 85 ($55) – a different colour scheme from the original ($31 and 5).

Apfelsee also occupies $6000 and more space from $C000Blue: used only by Apfelsee; grey: the same in bothHappy / FraktseeApfelseeColoursProgram $0801–$1B7CBitmap $2000–$3FFFGraphics ML $C000Colour RAM $D800ColoursLoader $0801–$1012Bitmap $2000–$3FFFMain program $6000F1 $C000–$C7B5Colour RAM $D800$0000$4000$8000$C000$FFFF
Figure 5: Memory map during computation, from disassembly and load addresses.

The area from $6000 is free in Happy and Fraktsee; Apfelsee uses it so that BASIC RAM and the bitmap remain untouched. The crosshair sprite additionally lives at $0340.

Colouring and Pseudo-Light

The programs compute no lighting. The impression of light and shadow arises solely from the order in which the sticks are painted over each other; the article only says “the light always comes from the right”.

How the Light Is Created

Every pixel draws a double column: white on the right (column 81 + HO), light blue on the left (column 80 + HO). The next pixel to the right paints its light blue column exactly over the white column of its predecessor, from its own top edge downwards.

Example 1: The Three Drawing Steps

Cone hill after the three drawing steps
Figure 12: With double columns alone the hill already looks three-dimensional: the right slope shows white remnants, the left one is uniformly light blue. The shadow lines darken the steep left slope; the surface pixels make the ground green and carry the contour lines.

Example 2: Light and Shadow on the Hill

Cone hill with labelled lit and shadow sides
Figure 13: The light shines from the right because the white column is on the right and is covered from right to left. It turns with the viewing angle: it is tied to the screen, not to the landscape.

Example 3: Lake Shore in the Fractal Landscape

Fractal landscape with enlarged lake shore
Figure 14: In the lake Z is negative; the surface pixels there are blue and merge with the background into a smooth surface. The 0.05 steps of the height create terraces; on every terrace edge a white or light blue remnant remains.

Colour Rules at a Glance

Colour Created by Effect
white right stick column, not painted over lit slope
light blue left stick column, covers the predecessor’s white shadow side, slope surface
blue (line) shadow line when C > CA + 0.2 deep shadow on steep steps
green surface pixel when Z ≥ 0 land, contour lines
blue (area) surface pixel when Z < 0, and background lake, sky

Program 1: Fraktal-Landschaft (Happy Computer 6/87)

The original is a BASIC program of 17 lines plus 16 DATA lines with 304 bytes of machine code. It is by Frank Göldner (text) and Hartmut Woerrlein (C64 version); the issue also prints versions for the CPC, Atari ST, Atari XL/XE and Amiga.

Fraktal-Landschaft: input screen and finished picture
Figure 15: Recreated screens: on the left the input with the values of the title picture, on the right the result in graphics mode with a black border. Texts and colours come from the listing; the font is modelled on the C64 character set.
Lines Task
1 poke machine code from DATA to $C000
20–70 border black, input X and Y, height at the position (GOSUB 270), input eye height and viewing direction
80 SYS XQ (graphics on), loop V = 1 to 600 step 2, E = H/V·10, loop HO = −80 to 80
130–160 compute HC, XC, YC, iteration, smoothing, lake test
250 compute C and clamp to ±98
261–265 the four graphics calls of the stick technique
266 endless loop: the finished picture stays on screen
270–272 iteration as a subroutine
32000–32015 DATA: graphics routines

Operation. No menus, no saving, no way to stop except RUN/STOP. The input is rejected if the eye height is below the terrain. The article recommends 0.2 to 1 unit above the position, because the plateau rises only two units above the lake.

Variant on the Crackpot disk. “APFELSEE – HAPPY” (tagged “Neue Version für Happy Computer von WO”) adds a menu (view graphic, save graphic, new graphic), a cloudy sky made of random ellipses and further machine routines at 49457 and 49478. These routines are missing on the disk, so the program does not run there as it stands. Pictures 6 and 7 in the Happy article evidently come from this version.

Speed. The article only says “sometimes several hours”. The BASIC interpreter has to parse every line anew and read four parameters from the program text for every SYS; for 48,300 pixels with up to 41 iterations each, this is the slowest of the three versions.

Program 2: Apfelsee (64'er Sonderheft 33)

Apfelsee by David Mehlhausen converts the Happy program step by step into machine language and builds a user interface around it. The article explicitly names Happy 6/87 as its model and calls Apfelsee “the currently fastest version”. The title in the program reads “APFELSEE – von David Mehlhausen – nach Gaston Julia und Benoit Mandelbrot”.

Apfelsee: main menu and coordinate dialogue
Figure 16: Recreated screens: on the left the main menu, on the right the dialogue after pressing fire on the map, here for position 0/0 in the lake, eye height 5 and viewing angle 0. Texts, line spacing and colours come from the code.

Structure

File Address Content
APFELSEE $0801–$1012, runs from $6000 SYS 2061, moves itself to $6000 with ROM routine $A3BF; menu, load/save, map, input, height of the position
F1 C000 $C000–$C6DF Happy graphics routines plus main loop and iteration
AUFSICHT PACKED $0801–$1081 self-unpacking map; saves “AUFSICHT” (bitmap $2000–$3FFF) when run

What Mehlhausen Took Over

What Is New

Lake Top View and Choice of Position

The AUFSICHT map comes as a finished packed picture; the program that created it is not included. On the left is the computation that reproduces the map at 93 %, on the right the code with which Apfelsee lets you choose the position on it.

Map AUFSICHT (recomputed)Choosing the position in ApfelseeFor every map pixel160 × 200 multicolour pixelsConvert to coordinates0.01 per pixel, origin at 80/144Swap axesvertical becomes 1st coordinateIterationsame lake formula, max. 41 steps41 steps without escape?yesnoLakeblueLandgreenNext map pixelat the end: saved packedThe map generator was not published;the recomputation matches 93 % of the pixels.Load and show AUFSICHTbitmap $2000, colours as in the pictureShow crosshairsprite 2 at 178/190, counters to 0Read joystick$DC00, counter ± 1 per stepFire button?noyesCoordinatesX = counter/200, Y = counter/100Compute terrain heightZ from 200, −5 per step, then ÷ 100Diese Position (J/N)?NJContinue in main floweye height and viewing angle
Figure 6: Lake top view and choice of position: Apfelsee $62CF–$6504, recomputation of the map.

One map pixel corresponds to 0.01 units in both directions, because the joystick counter counts horizontally in hires pixels (two per multicolour pixel, divided by 200) and vertically in rows (divided by 100). The map thus shows 1.6 × 2.0 units, horizontally from about −0.8 to +0.8 and vertically from about −0.55 to +1.45; the channel starts at the top centre.

Speed

The article gives about two hours per picture, with the 4 MHz card barely more than half an hour. The gain over Happy does not come from the arithmetic – it runs through the same ROM routines – but from dropping the interpreter, the parameter parsing for SYS and part of the interrupts. A typical picture needs about 1.8 million iteration steps by my calculation; two hours thus correspond to about 4 ms per step including projection and drawing.

Program 3: Fraktsee (64'er Sonderheft 57)

Fraktsee is the Happy listing in compiled form, wrapped in two packer layers. The article names Frank Michlik as the author; his name does not appear in the program itself.

Fraktsee: title screen and input screen
Figure 17: Recreated screens: on the left the title screen, on the right the input screen with the values of the title picture. Texts, line order and the colour codes blue and red come from the unpacked program; background, border and the white text are assumed.

Layers of the File

  1. fraktsee.prg (4,891 bytes, SYS 2062): packer 1 moves the data to the end of memory, unpacks it to $0801 and returns to READY. That is why the article asks for a second RUN.
  2. Layer 2 (SYS 2080, tag “THC 3001”): a second packer that puts the code at $0801–$1B7C and the graphics routines at $C000 and starts the program.
  3. Program (SYS 2076): compiled BASIC from $081C with jump table, runtime library and title screen.

Evidence for the Origin

Feature Finding in the unpacked Fraktsee
Machine code $C000–$C12F 304 bytes, byte-identical to Happy DATA 32000–32015, including the six unused trailing bytes
Variable table X1, Y1, XQ, XW, Z, XC, YC, XA, YA, H, KU, SI, CO, V, E, HO, FA, HC, ZA, C, CA, X2, Y2, XN – exactly the Happy names
Constants 0.0187, 0.7, 0.3, 0.0001, 0.2, 0.05 as 5-byte numbers; none of the cloud constants
Source text remnants “,81+HO,98-C,199,2:” and “,80+HO,99-C,99-CA,0”: the SYS parameters from Happy lines 261 and 264, which the compiler keeps as text for parameter parsing
Title screen “The Highlight Company 3001 is proud to present: Fractal Calculate (c) in 1987 by Markt & Technik”
Input texts “Enter Coordinates”, “X-Axsle”, “Y-Axsle”, “The height is … here”, “Your height”, “Visual angle”

Markt & Technik was the publisher of Happy Computer and 64'er. The article texts are also closely related: “In Richtung Nord (0 Grad) liegt die positive X-Achse …” (“North (0 degrees) is the positive X axis”) appears almost identically in both issues.

Operation and Limits

Speed

Compiled BASIC saves the parsing of program lines but still calls the same ROM floating-point routines and, for every SYS, the parameter parser. It therefore lies between Happy and Apfelsee. The article nevertheless speaks of “several hours”. The “Fahrplan” table in the issue gives 15 locations.

Comparison of the Three Programs

The programs differ in execution, operation and speed, not in the picture: the same input gives the same landscape.

Feature Fraktal-Landschaft Apfelsee Fraktsee
Origin
Published in Happy Computer 6/87 64'er Sonderheft 33 64'er Sonderheft 57
Author according to the issue Frank Göldner, Hartmut Woerrlein David Mehlhausen Frank Michlik
Publication form BASIC listing + 16 DATA lines 3 MSE hex listings program on the issue disk
Language BASIC V2 + 304 bytes of machine code pure 6502 machine language compiled BASIC + 304 bytes of machine code
Size 17 lines + 16 DATA lines 2,066 + 1,760 bytes, map 2,177 bytes packed 4,891 bytes packed, 4,961 bytes unpacked
Start RUN LOAD, RUN; moves itself to $6000 LOAD, RUN, RUN again (two unpacking stages)
Operation
Language of the dialogues German German English, with title screen
Menu no View, Load, Save, New picture no
Choice of position number input X, Y joystick on the map, then height and angle number input X, Y
Viewing angle 0° along the 2nd coordinate top edge of the map (compass) as Happy
Abort RUN/STOP ← key RUN/STOP + RESTORE
Save / load picture no yes, bitmap $2000–$3FFF only externally (Super-Saver, Fraktlader)
Computation
Iteration |x| − |y| − XC; 2xy − YC identical identical
Height and steps Z = 2 − 0.05·n, at most 41 steps identical identical
Height of the position Z from 2 in steps of 0.05 Z from 200 in steps of 5, then ÷ 100 as Happy
Smoothing 0.7 · neighbour + 0.3 · value identical identical
Raster 300 rows × 161 columns identical identical
Floating point BASIC interpreter with ROM routines ROM routines called directly ROM routines via compiler runtime
Graphics
Graphics routines original $C000–$C12F $C059–$C129 byte-identical, init/clear swapped byte-identical
Call SYS with parameters in the text JSR, parameters in zero page SYS with parameters in the text
Colours blue, light blue, white, green identical identical
Speed
Interrupt normal (60 Hz) throttled to about 15 Hz, without clock normal
Screen off no SHIFT LOCK, about 6 % faster no
Turbo card no 4 MHz card Turbo Process no
Time per picture according to the issue “sometimes several hours” about 2 h, with 4 MHz about 30 min “several hours”

The Three Programs’ Pictures Compared

The same view from Fraktal-Landschaft, Fraktsee and Apfelsee
Figure 18: The same view in all three programs: position 0/0, eye height 5, looking along the channel (Happy angle 90°, in Apfelsee 0°).

All three programs deliver the same picture pixel for pixel.

The comparison shows 0 differing pixels out of 32,000. The different angle in Apfelsee exactly compensates for the program internally swapping X and Y as well as sine and cosine.

Picture Build-up

Picture build-up after 21, 61, 151 and 599 rows
Figure 19: In the first rows the sticks reach the bottom edge and the lower half is light blue; only the nearer rows paint over it. The light vertical stroke at the edge comes from stick column x = 161, which the address calculation places in a different character row.

The Map AUFSICHT

Unpacked map AUFSICHT next to the recomputed top view
Figure 20: The map from Apfelsee shows only lake (blue) and land (green). It is a top view of the same formula in the coordinate system of the joystick control; after compensating for a crosshair offset of about 6 × 4 pixels, 93 % of the pixels match.

The Happy article shows the same top view as a schematic drawing with the positions of its sample pictures. It is rebuilt here; the shoreline is computed with the lake formula and smoothed, the positions are transferred from the original.

From a bird’s-eye view you choose the positionXY0.511.5−1113456710Positions of the picturesntip = viewing directionlake (41 steps)shore from the lake formula,computed and smoothed;positions after HappyComputer 6/87, picture 2
Figure 7: Schematic map after Happy Computer 6/87, picture 2: shoreline computed, positions transferred.

The original is not to scale: there the lake body is drawn flatter and wider. Its Y axis corresponds to the first coordinate of the iteration, i.e. the vertical direction of the Apfelsee map; the channel runs upwards in both representations.

From Height Field to Picture

Drawing uses the painter’s algorithm from back to front. The variable V runs in steps of two from 1 to 600 and stands for the screen row below the horizon; from it follows the distance E = 10·H/V. For each of the 161 columns, HC = E·HO·0.0187 gives the lateral offset, which corresponds to a field of view of about 112°. The screen height of a point is C = (Z − H)·V/H.

Water level, height 0Horizon = screen row 98EyeHScreenScreen row V below the horizonC = (Z − H)·V/HZDistance E = 10·H/V
Figure 8: Side view. Every screen row V below the horizon belongs to a distance E; a point at height Z appears C rows above or below the horizon.
Viewing directionEHO = −80−40+40+800lateral offset HC = E·HO·0.0187≈ 112°Position161 columns per screen row
Figure 9: Top view. At every distance the program spreads 161 columns over a viewing cone of about 112°.

Every column is filled from this height down to the bottom edge of the screen, and nearer rows paint over more distant ones. Everything behind a mountain thus disappears without the program having to compute visibility.

The height of every column is taken 70 % from the left neighbouring column; this produces the typical slanted stripes. That V runs up to 600 even though the screen ends much earlier is explained by the Apfelsee article as a dead angle: someone looking straight ahead still needs to know how high the ground is in front of their own feet.

Colours and Pseudo-Shadows

In multicolour mode each tile of 4 × 8 pixels may show only four colours. Fraktsee sets them the same for the whole screen and gives each one a task. Green is the surface: in each row the program colours only the top one or two pixels of a column green. On flat terrain the rows are at most two pixels apart, so the green edges join into a closed meadow. When the terrain becomes steep, the rows move apart and cyan, the fill colour of the columns, appears in between; it looks like rock on a slope. Blue is the background colour and has to serve three purposes: as sky, as the water of the lake and as shadow. Because sky and lake have the same colour, the water looks as if it reflected the sky.

There is no real lighting calculation with surface inclination or cast shadows. The impression of a light source on the right arises solely from the drawing order and the comparison with neighbouring columns. The routine $C0E9 paints every column in cyan and next to it, one column further right, a white stripe. The next column paints over this stripe again with cyan from its own top edge. If it is lower, a piece of white remains above: slopes falling to the right shine as if lit by the sun. Conversely, the program draws a blue line from the new to the old top edge when the terrain rises by more than 0.2 (measured in screen rows) compared with the left neighbouring column. These slopes face away from the light source and appear dark. This is a pseudo-shadow: it only colours the averted slopes themselves and never falls on the terrain behind. Together with the slanted stripes of the smoothing, this is enough to turn four colours into a three-dimensional landscape.

Two image rows of a small hill, pixel by pixel
Figure 21: Two image rows of a small hill, generated pixel by pixel with the program’s drawing rules. On the left the terrain rises and gets shadow pixels; on the right it falls towards the sun and shows white lit edges.

Sticks Up Close

Cone hill with summit and enlarged summit
Figure 22: The fractal landscape has hardly any free-standing peaks. To make the technique visible on a clear hill, an artificial cone hill (height 1, radius 0.1) was inserted into the drawing logic; projection, smoothing, colours and graphics commands are unchanged.

Computing Effort

View (X/Y/height/angle) Iteration steps per pixel
0/0/0.5/270 1,941,292 40.2
0/0/3/0 1,822,616 37.7
0/0/5/90 1,762,450 36.5
−1/−1/4/90 411,548 8.5

Every picture has 300 × 161 = 48,300 pixels. Views showing a lot of lake are almost five times as expensive as views over land, because lake points always run through all 41 steps.

Sample Views

Six views from the Fahrplan table
Figure 23: The locations come from the “Fahrplan” table in Sonderheft 57 (heights and angles in Happy convention). In Apfelsee the angle w corresponds to the Happy angle 90° − w.

Quirks and Corrections

Four flaws of the original can be corrected in the reconstruction. The smoothing is not reset at the end of a row, so the right edge of the picture affects the left edge of the next row. The last column draws beyond the right edge and lands eight pixels lower on the left. And because the screen height is clamped to ±98, the bottom rows never get their surface colour and stay light blue. If you stand only just above the terrain, the computation also ends after 600 rows before the near ground reaches the bottom edge of the screen; light blue rows and stripes remain there. The corrected reconstruction continues the ground colour of the last row down to the edge.

Original and corrected, with numbered markers
Figure 24: On the left the original, on the right with all four corrections. The numbers mark the effects in the order of the text: 1 smoothing across the row change, 2 overflowing last column, 3 light blue bottom rows, 4 ground not reached.

Uncertainties and Open Points

The core statements are backed by byte comparisons and recomputation; some details rest on assumptions.