Fly over Amsterdam with ClojureScript

01 Apr 2018

Controls: Arrow keys Speed: Page Up & Page down

Center stick: Enter Restart Enter + Shift

Switch flight/camera mode: C

Some time ago I came across a very tiny but potent program. It is a flight simulator in under 2kb of code. This program from 1998 was written for the Obfuscated C contest by Carl Banks. In this program you fly a tiny airplane through a wireframe 3d world.

As I have little experience with 3d programming, I was curious to figure out how this program worked. Therefore I made a version in ClojureScript. In this edition you fly over my home town of Amsterdam, instead of Pittsburgh from the original. Here you can enjoy the layout of the canals rather than a sky full of skyscrapers as Amsterdam isn't really known for its skyline. There is also a row of windmills.

Obviously, it is not easy to figure out how a program works from obfuscated code. This partial de-obfuscated version was very helpful in learning how to render the world with the airplane as the camera or viewpoint. I still haven't figured out how the flight mechanics of the plane work, so the ClojureScript version has a more arcade style of flying.

Evidently, all the rendering and controls can be handled by shoving all the math through a single matrix. I also did not manage to get that to work, so instead the program does a bit more math in separate steps. This means that the program does more calculations than necesarry. This makes your laptop fan spin, which sounds like the propellor of a tiny airplane, which is a feature.

Finally, the original program was skillfully fit into obfuscated C. With ClojureScript's advanced compilation with the Google Closure Compiler the obfusciation is provided for free.