Posts in May, 2007

I had a little spare time to do some work on postmarkup.py, my BBCode module. It now handles Unicode correctly, which was a big omission, considering its intended use. I also added a few other features. The tag parameter string can now be specified in 3(!) different ways. For example, the following 3 lines are equivalent.

[link="http://www.willmcgugan.com"]My homepage[/link]

[link http://www.willmcgugan.com]My homepage[/link]

Another addition, is an [img] tag.

There is also support for lists (ordered and un-ordered), with the phpbb syntax. For example:

[*]Apples

[*]Oranges

[*]Pears

[/list]

This produces an un-ordered list. continue reading…

The Triops have started on solid food. They seemed un-interested in the food at first, but once the pellets swelled up with water the little darlings had a nibble. The instruction booklet says that after a week you can feed them tiny pieces of carrots and fish. I had some Australian Snapper fillets in the fridge for my dinner, so I snipped of a little piece and chopped it in to Triop sized morsels. Ive never tried snapper before, but it must be delicious - judging by the macabre feeding frenzy that ensued. Mental note: be careful about getting fingers in the water when they get a little bigger. Triops don't want to be fed, they want to hunt. Can't just suppress 65 million years of gut instinct!

Update: The snapper was indeed delicious.

I enjoy optimizing code. These days I don't get the opportunity to do it very often, since I prefer working in high level languages now. Which is why I have been particularly enthusiastic in optimizing the 3D math classes in Game Objects. continue reading…

I've just uploaded a new version of Game Objects. The 3D maths classes (Vector2, Vector3 and Matrix44) are reasonably stable now. I'd like to invite Python coders to play around with them, and suggest any improvements. My intention was to make something that was very easy to use, but well optimized. Game Objects is public domain. Do what you want with the code - go crazy!

There is no documentation at the moment I'm afraid, but here are a few edited highlights.

I don't often say this, but I miss something from C++ that I can't do in Python. What I miss is unions. I know they can be dangerous and aren't supported consistently across compilers, but damn it, they can occasionally be useful.

I'm working on a 4x4 matrix class (for 3D maths) as part of my Game Objects library. It's something I have done several times in C++, where I create a union of a two dimensional array and four Vector4 classes. That way the matrix is conceptually both a grid of numbers and four vectors, which allows for quite elegant code. For example if I have a CMatrix class that stores the transform for a spaceship and I want to move it forward 2 units, I might use code like this. continue reading…

Many moons ago I implemented Langton Ants on a ZX Spectrum 48K, and I have been fascinated by it ever since. I thought it would be fun to implement it in PyGame.

Langton ants are simple creatures. They live in a grid of squares that can be one of two colors, and follow these two simple rules.

That is all they do. They don't ponder the meaning of life or current affairs, they just check the color of the square they are on and then turn and move. You would think that something this simple would quickly get in to a cyclical pattern, but it turns out that Langton ants like to make crazy complex patterns and don't repeat themselves. Humor me, while I write a Python script to test it.

First thing we need to do is define a few constants for use in the script, as follows. continue reading…

My triops hatched today. I am now the proud father of four tiny crustaceans, and there are more on the way. They are barely visible - just little white specs, but I can make out a pair of swimmerets.

Apparently they double in size every day. They are about a millimeter in length at the moment, so by this time tomorrow they will be 2 millimeters long. They live about 60 days, so eventualy they will be 2 to the power of 60 millitmeters in length. Let's see... thats 1,152,921,504,606,846,976 millimeters, 1,152,921,504,606,846 meters or 1,152,921,504,606 kilometers (*). Oh. My. God. We're gonna need a bigger boat.

* For Americans, that's 716,392,209,599 miles

sea monkeys. If you are not familiar with sea monkeys - they are a kind of brine shrimp that has been marketed as a kids toy. They come as a little sachet of eggs with a plastic tank. You add water and they hatch within hours. It's the most marvelous, stress-busting executive toy you can buy. I loved my sea monkeys so much, it inspired me to write an artificial life demo (for PC). continue reading…

I use my laptop for instant messaging and picking up my email while I'm working. It's not quite as good as having dual monitors but it means I can easily work and chat / refer to emails without having to shuffle windows about. Occasionally I need to transfer something from the laptop to my main machine - which can be a pain because I have to minimize windows, find the file, drag it on to a shortcut then find it on the other desktop. What I want is to be able to access the clipboard on the laptop from my main work PC, so that all I would have to do to copy a file from my laptop would be to copy it to the clipboard then press, say Shift+Ctrl+V on the other machine to suck it over the network. And I want it to work with text, urls and anything else that can be copied to the clipboard. And I want it to be free. :-)

A recent post on reddit.com sparked a debate on the following snippet of C code.

The denizens of reddit have been musing over the the output of the code; is it 13 or 14? It can be either depending on the compiler used - or something else entirely - as the result is undefined, which another denizen noted. Sometimes I wonder if the C language was designed purely to provide challenging job interview questions.

Even though I was a C/C++ programmer for a lot longer than I have been a Python programmer, the entire concept of a valid language construct being undefined is offensive to me. Seriously. It's like month old milk; makes me screw my face up and turn away in disgust. In contrast, Python smells like a mixture of freshly cut grass and new car smell. continue reading…