Lunchtime coding challenges

Last week, I was asked for some help with a simple coding problem; to simulate the orbit of a moon around a planet. It's not a hard thing to write and with a little school-level geometry and the solution is simple (the hard part being that school was 25+ years ago).

I chose to write in JavaScript to an HTML canvas as it's a quick way to throw together basic graphical applications with minimal effort. Back when I was at school, this would have been a job for Sinclair BASIC which was immediately available and provided the entire environment necessary: a simple language with integrated (if rudimentary) graphics support. It seems to me that things are a little more complicated these days.

I didn't want to do this to for any reason other than it sounded like a bit of fun, and I think that it's necessary to sometimes take a break from your day job and distract yourself with a different problem.

These little coding challenges are good for a few reasons:
1. Building a small project gives instant gratification.
2. Doing something different can help clear your head.
3. They let you learn new techniques.
4. You can play with unfamiliar parts of a language.

Here's the end result.

If you're interested, the source is available on github:

git clone https://github.com/adam-cant-run/planetary-oscillator