Skip to main content

Fun with planets

screenshot Over the holidays I finally got around to doing some recreational coding again. The results even surprised me so I thought I’d share it with my blog-readers. So here it is, your very own planitarium. Planets flying around with real gravity just like Newton taught us (who needs all that fancy new-fangled relativity anyway), and if you feel like it you can even play God and slingshot planets into outer space. Just try clicking anywhere in or around the window.

I also included the source code although I’m not particularly proud of it. I’ve spent more time playing with the program than actually writing nice code. It’s been a long time since I’ve actually written code without tests. The code itself is quite simple. There’s a galaxy object that contains and handles all the planet interaction. There’s a body object that comes in two flavours, a normal one and a mousebody that represents the mouse position. They both implement IBody so the Galaxy doesn’t care what bodies there are. The normal body objects fly around. The MouseBody always has the position of the mousepointer and only has mass when you push a mousebutton.

That’s about it. There’s a planetariumview and a presenter object that handle painting the whole planet stuff. There’s a Time object that wraps a timer for the heartbeat and there is a program that wires it all together.

Enjoy! and let me know if you do anything fun with it.

Code:

Planetarium.rar (13.85 kb)

Binary:

Planetarium.exe (16.00 kb)

Comments

Popular posts from this blog

Using xUnit.Net with .Net 4.0

I’ve been using xUnit.Net for a while now. It’s just a tiny bit cleaner and slightly less abrasive than other .Net unit testing frameworks. Leaving out unnecessary stuff like [TestFixture] and shortening Assert.AreEqual to the equally clear but shorter Assert.Equal don’t seem like big improvements but when you type them several times a day tiny improvements start to add up. I also like the use of the [Fact] attribute instead of [Test]. It shifts the focus from testing to defining behavior. So how do we get all this goodness working with the Visual Studio 2010 beta?

Square One available on the Android market

This is just a short post to let you know that a first version of the Android app I’ve been working on for the last couple of weeks is available on the Android market. The app is called Square One and it’s a simple bassline synthesizer. It’s free so try it out and let me know what you think of it, but be prepared it’s still an early version. I hope to add more features in the next few months and maybe build something that can be used to create real music.The lower part of the screen contains the sequencer controls that can be used to program your own bass lines. On the left is a four by four grid of buttons where you can select a step in the sequence. On the right you can select the note to be played on that step. When you’re done you can press Start and the sequence starts playing. The knobs on the top can be used to control a couple of parameters from the synthesizer engine that creates the sound. You can control the cutoff frequency and resonance of the low-pass filter, attack and …

Building Android projects with Jenkins, Ant and Mercurial

I have recently set up a Jenkins build server for my Android projects hosted on Bitbucket. It’s not difficult but there are a couple pitfalls and the information on how to do this isn’t available from one single place so I decided to document the process and put up the information over here. Maybe other people will benefit from having a step-by-step guide too.