Site logo,

The Forest - orienteering simulation

A major aim of The Forest, from its earliest version more than 35 years ago, has been to help people interpret the contour information in maps. That enables orienteers to navigate without just following roads or streams, it helps hill walkers to avoid getting lost, and more generally it helps anyone reading a map to get the most out of it.

This program includes some non-trivial games and diversions for those who are not orienteers (we will call them explorers, which relates to another version published in the 1980s).

The program described here demonstrates a technique for generating vast terrain by an algorithm rather than storing it in memory or having to download it as a huge amount of data. It is written in JavaScript for an HTML5 web page and the program occupies less than 200 kilobytes, so it downloads and runs almost instantly. Nevertheless it has more than 1,000 sq km of forest to explore (very much more!).

Try it: The Forest

Simple URL:

QUICK START: use arrow keys or tap/click inside edges of the map or scene.
Key m or click button to switch map & scene.More detail...

There are three views of the terrain available in The Forest:

Although there are buttons to tap or click for switching between these views there are also keyboard alternatives indicated on the buttons.

A scene in The Forest

The view from a point in the forest

The visible range for this particular view was set to 400m which takes much longer to compute than the initial 60m range when the program starts. Your maximum practical range depends on how fast your machine is. A number of choices are available from a drop-down list on the page.

Part of the map, with the above viewing point marked

Map showing the previous viewpoint

This part of the map is only a tiny fragment of the whole forest. It effectively goes on for ever, though the contours repeat every 32.8km.

The red marker encircles the viewing point. It has a point which indicates the direction of view for the scene above. This red marker does not appear for non-novice orienteers, once such a role has been selected (see below).

Notice that every fifth contour is thicker than the others. This is normal on orienteering maps. If you study the map you will see that this thickening helps to interpret whether some contours are up or down from neighbouring ones.(O-maps also use downward-pointing tags on some contours to help further. There does not seem to be a way of doing this automatically and reliably.)

Scale is given by the fact that the black north lines are 300m apart. 1 pixel in the display represents 1 metre on the ground. Actual size depends on the size of your display screen.

3-dimensional plot centred on the same point

3-dimensional plot centred on the same point  

 Interacting, to control the program

It is hoped that the user interface is reasonably intuitive. Please read what is presented beneath the map or scene.

Interaction can be by keys on a keyboard or by clicking with a mouse or, on touch screens, by simple tapping on the relevant button or screen area.

The inner edges of the scene or map can be clicked or tapped for the 4 directions that are equivalently selected by arrow keys.

When a map is displayed the edges or arrows scroll or pan the map in the corresponding direction.

When a scene is shown,

Below the map or scene there are various buttons, such as this one:
This example shows that instead of clicking or tapping on it you could press the m key on a keyboard.

Apart from buttons there are other standard types of web page controls, such as drop-down lists.

In particular you should look at the drop-down list marked "Role" and choose one.

 Map and 3D plot

The map has 4 states, selectable from a drop-down list:

All show north lines 300m apart.

Printed orienteering maps declare their scale and contour interval but we cannot do that here. The scale depends on the size of your display screen. However, 1 pixel on the map represents 1 metre on the ground and the initial map is 800 pixels wide and 600 high. The north lines indicate the scale because they are 300m apart. The vertical scale in the scene display is rather arbitrary, so it is not possible to say what the contour interval is either. Just assume it is the usual 5 metres.

The map can be rotated clockwise in steps of 90°. North lines on the map have black arrows so that when the map has been rotated the direction of north is clear. Some orienteers find it easier to relate the map to the ground if it is oriented roughly to the direction they are facing.

As of version 18.12.20 the map can indeed be oriented so that the direction you are facing is straight upwards.

The aim of the 3D plot is to help people interpret contour lines on the map. It may take several seconds to draw the plot - rather longer than the scene or map views.

Version of the map showing area of 3D plot

Map showing area of 3D plot

 The scene view

The scene view indicates what the observer would see from an eye level 1.5m above the ground. The view indicates whether the ground ahead slopes up or down, according to the contours on the map. The type of terrain ahead is indicated by graphics. One of the advances here is that real photographic images are used rather than simple drawn graphics. The ground is drawn in true perspective out to a certain distance ahead (the visible range). Initially this range is set to 60m but you can select greater ranges. You will soon find that if the range is too great it will take an appreciable time to draw the scene (depending on the speed of the processor in your computer). For moving through the forest it is desirable to keep the scene drawing time to less than about a fifth of a second (200ms) The drawing time is shown in a status line below the display.

The arrow keys are active in the scene and they act as follows.


  1. The arrow keys may scroll/pan the window in some browsers or on small screens, so letter key alternatives are allowed: initials of Right, Left, Up , Down (upper or lower case).
  2. On touch screens it is possible to tap near the edges of the scene or map instead of using arrow keys. On a PC a mouse click just inside an edge of the image will also work.
  3. For explorers in certain situations the Enter key is significant (or on touch screens tap near the centre of the scene).

Note that the observer's current position (x, y) and bearing (degrees clockwise from due North) are shown in the status line at the bottom of the view. A compass is also shown at the bottom centre of the scene view.

Shallow lakes may be crossable but if the depth becomes greater than a couple of metres you will be told you are out of your depth and you will be turned around to swim back to the shore. So venturing into lakes can be very time-consuming.

Why do level things such as lakes appear to slope down at the edges of the scene? Because we are viewing a circular disc patch of ground from a small eye-level distance above it. The effect becomes less as the visible range is increased.


Drop-down list of possible roles

The observer mentioned above may have one of several roles:

 Orienteering courses

If you are not familiar with the sport of orienteering you may like to read this: British Orienteering Newcomer's Guide

Drop-down list of orienteering courses

 The easy short course

Map showing the short easy orienteering course

 At the finish

When an orienteer completes a course the full control card and a table analysing the route are shown:

A completed control card Results analysis table

As of version 18.8.15 there is also a button above the results table for causing the actual route taken to be plotted on the map. This also means that automatic reversion to the role of Explorer does not occur until the results are cleared.

How is it that the orienteer can sometimes complete a leg of the course by travelling less than the crow-fly distance? Easily because it is only necessary to be within 5m of a control for it to be punched. By approaching and leaving controls in the right direction it is possible to cover up to 10m less than the actual distance between controls. This is not just a feature of this simulation: it now happens in the real sport because electronic devices are used for automatic punching when within 5m of a control.

Try it: The Forest

 The score event

Map showing the start and finish of the score event

This is part of the map for the start of the score event. As for other courses, the purple triangle is the starting position and the double circle is the finish. The numbers alongside the control circles are points which can be scored by visiting the controls (by getting within 5m). Scores are proportional to the distance of the controls from the finish point. You can choose which controls to visit, in any order. Once a control has been visited it cannot be used again.

There is a time limit. You must reach the finish within 1 hour. Otherwise there is a penalty to be deducted from your score, based on the number of seconds you are over the hour.


A recent development (2018 November) introduces buildings occupying definite 3-dimensional spaces rather than being merely flat photos. These are more of an obstacle to orienteers because it is no longer possible to just run across their patch of ground. Instead it is necessary to steer a path along the 4-metre-wide alleyways between the buildings.

The buildings are arranged in a regular grid arranged exactly north-south and east-west. They are shown on the map as black squares on a grey background indicating the paved area on which they stand.

A view of some buildings Buildings plotted on the map
[This scene and map fragment are of different places in the forest]

There is a door on every building but it may not be on a visible side. The doors are all different colours. It is possible to enter the buildings if you know the key code specific to each door. This will not be of any interest to orienteers but explorers following the treasure hunt will find clues. There are things to find inside buildings.

 Additional keys

Some keys have effects which are not represented by buttons or other controls on the web page. They only work unshifted (lower case). They are perhaps experimental and may or may not develop into something more.

 Two windows

On a PC (but not on a tablet or phone) you may well have room on the screen for part of the map alongside the scene on the ground. This can be achieved by having two browser windows open, each with a copy of the program running in it:

Map and scene side by side in 2 windows  

 Course planning

As well as the permanent courses supplied with The Forest, orienteers can make their own. Furthermore there is a facility for such courses to be sent to others to plug into their copies of The Forest. These courses are held within each user's own browser; nothing is sent to the server.

The point is that a team trainer can plan courses and send them to team members to try on their own machines.

On selecting the role of course planner, two buttons appear: either a new course can begin to be planned or a new web page can be opened for managing the available courses.

Making a new course

The first button, to begin a new course, further changes the page to provide other buttons, which remain visible whether the map or the scene is being viewed.

The options are as follows. The map is redrawn with course symbols as the course is built up.

You would then change to another role to complete the course planning process.

Managing courses

This button takes you to a new web page that lists existing courses and allows several things to be done with them.

The first few courses listed are the fixed ones that are supplied as part of The Forest. Then your own courses are listed. There are 3 possible actions for these lower rows of the table:


 Explorers: games for you

A mine shaft

Explorers can see things in the forest which orienteers cannot (orienteers are not to be distracted). Some of these things will suggest a target to aim for (more achievable than in my 1980s Explorer version of this program: see Pixelatron).

Where orienteers would see a traffic cone, not marked on the map because it is potentially movable, explorers will find something else. Out in the open cones are replaced by aircraft that may be boarded to get aerial views. In woodland there are instead posters with writing on giving some clues for finding treasure. The clues are written in a code which the explorer will have to decipher. (This vocalian code was devised many years ago by Kevin Cook when we were school friends.)

Also, explorers will fall down mine shafts if they get too close (orienteers are immune to this). There is an underground level to explore and it is possible to get back out again because there are some ladders.

NB: For explorers in certain situations the Enter key is significant (or on touch screens tap near the centre of the scene).

You will inevitably want to copy and save images of some of the things you see but this program does not provide any such facility. Instead you will need to use a screen copying program in whichever system you are running, such as the Snipping Tool in Windows.

Hint: there is a short-cut, described in this page, for something which may at first seem very lengthy in your task.

Hint: the target location is within the first 32km block of the forest (the status line will show coordinates lying in these ranges: 0 < x < 32768 and 0 < y < 32768).

There are also several examples of a green door in a wall, to be entered to see a completely different view. Once again, there is a way back to the normal world but it may be difficult to work out.

 It's raining

Something else which explorers can experience (but orienteers will not want to be bothered with) is changing weather. Rain causes the levels of lakes to rise. When it stops and the sun comes out, the levels fall back. A message appears briefly when lake levels are back to normal. This illustrates that the terrain can change. Earthquakes would change the topography more drastically and that could easily be programmed but it has not been done (yet).

 Aerial views

Where orienteers might see a traffic cone on open ground, those in the role of explorer will instead see a helicopter. When within 7m it is possible to board the helicopter and ascend to view the terrain from above. This gives a new perspective in more than one sense: by switching between scene and map it is then possible to get a different idea of the relationship between contours on the map and the relief of the terrain. It may be useful for orienteers to try this.

The helicopter can only land (reduce altitude to 0) on open ground. It remains where it lands and may be used again.

Interestingly (to programmers and mathematicians) the aerial view reveals patterns in the planting of trees, patterns which are not apparent at ground level. This is particularly the case for thickets because the tree images there are more similar to each other than in the mature wood. The patterns are reminiscent of those arising in cellular automata and will be a property of the algorithm used for positioning the trees, based on binary digits of multiples of pi.

 The status line

Below the map or scene, near the bottom pf the HTML page, there is a status line which is rewritten every time the display changes. An example when a scene is displayed looks like this:

x = 15233.55, y = 5755.24, bearing 156°, steepness = 13, Drawn in 309ms (7309 images)

You may be interested to watch how the number of images and the time taken change as the visible range is altered via the drop-down control. They should go in proportion to the square of the range.

The status line is simpler when a map is shown, just giving x and y for the centre of the map and the time it took to draw.

If you make a note of them you can use the x and y coordinates to get back to any place in The Forest (but not if your role is orienteer, on a course).

 Optional effects

Beneath the status line there are some check-boxes which enable certain effects to be switched on or off. Depending on the efficiency of your browser these may or may not cause scene drawing to take longer (try them and see).

A view with maximum detail and hazy horizon
A 300m view with maximum detail and foggy horizon both switched on

 Optional URL parameters

It is possible to control some of the settings when The Forest first starts, by adding optional parameters to the URL (its internet address). This is done by appending a question mark (?) to followed by a number of "name=value" pairs separated by ampersands (&). For example,

This example would tick the "Max detail"check-box and set the visible range to 150m.

The full list of possible parameters follows.

 Latest changes and further development

Recent and planned changes are summarised on the "What's new" page. I am open to ideas for further enhancements.

 Further information

There are some pages about my orienteering maps of real forests here. Follow the links there to read more about the maps for the original ZX Spectrum simulation of orienteering.

In particular there is a page about why The Forest is designed the way it is, which I wrote in the mid-1980s. It still has some relevance, especially about why I do not attempt to use maps of real forests (a scarce resource in the UK).

I started developing the new HTML5/JavaScript version in 2014 but it was heading more towards my second Spectrum program, Explorer (published by Electric Dreams in the mid-1980s). It included the possibility of falling down mineshafts and navigating underground. It also included a teleportation feature whereby typing a string of characters would take you to a new position on the map, seemingly at random but the same string would always go to the same place. Having got those features to work I rather lost interest in that development and shelved it.

My interest began again in February 2018 with an email out of the blue from Graham Scott of NATO (Newcastle and Tyneside Orienteers). He and I had been members of Tyneside Orienteers (as it was then) more than 30 years ago. I decided to complete the program as a purely orienteering project. Try it: The Forest


I first used the terrain generating method in the early 1980s in a program for the Sinclair ZX Spectrum, a machine having only 48 kilobytes of useable memory. That program simulated the sport of orienteering quite successfully despite the severe limitations of the technology. More details can found in the history page which includes a link to an archive for obtaining the old program and running it on a Spectrum emulator.

I am keen for other programmers to learn about the technique and perhaps take it further, so the source code of the new program is easily viewed.

The Forest demonstrates that JavaScript engines in browsers are now very fast. So client-side JavaScript in an HTML5 page can be an effective platform for games, avoiding large data downloads. It has many advantages: it is available on a very wide range of devices without needing any adaptation for each and does not require to be accessed through any application program ("app") store.

The original versions of The Forest and Explorer were written in Z80 assembler, in order to fit into the very limited amount of memory available and to run at a reasonable speed (much faster than interpreted BASIC). The new version is written in JavaScript, a much more easily comprehended language, running within an HTML5 page and doing the graphics within <canvas> elements. If you right-click and "view source" on the page you can see the file names for the JavaScript files and therefore view them also in your browser, to see how it works. If you are not familiar with JavaScript, particularly its object-oriented aspects, you may wish to peruse my free introductory programming course.

Note again that the program runs entirely in your browser. After downloading the program and images the server has no further involvement. The browser does all of the hard work of course, and that is a very much larger program. I am amazed by how much detail it is now possible to show in real time by writing some JavaScript and running it in a standard browser.

The contours and terrain types repeat after 33km (32768m to be precise; older programmers will recognise that number instantly) but the point features do not repeat like that.

I am documenting aspects of the software design here.

Programming challenge

If you are already a JavaScript programmer you will be able to explore my code. Then you might like to try this:

Find the (x, y) coordinates of the highest point on the map (in the first block of the 32km repeating terrain, starting at 0, 0). Is this point unique (are there any other points at the same height)? Do the same for the deepest points in the lakes. Please email me with the answers, at gr[at]grelf{dot}net - I will be interested to see whether anyone does this. It doesn't take much code.


Try The Forest:

Detailed history of The Forest (the next page here).

A 1984 review of the original version, in Crash magazine.

A programmer's guide to The Forest is also being written.

If you wish to learn to program you could do worse than follow my JavaScript course, based on training I used to give professionally.

British Orienteering Newcomer's Guide

My own orienteering maps

Food for thought: Philosophy of The Forest

Next page