Gwbasic Demonstrates Chaos

Back when in my late teens my older brother brought home a program that was supposed to demonstrate some of chaos theory. He originally wrote it in QBasic but I have reconstructed it here for gwbasic.

It’s a fairly simple construction, you have an “Ant” which can move in any one of 8 cardinal directions like that on a compass. Instead of being labeled North South etc, each direction is given a number 0-7 like in the diagram. As the ant moves around the screen it changes the colour of the pixel it moves over increasing its colour by 1. when the colour reaches its limit (in this case 15 as it is an EGA mode) the colour is cycled back around to 0. When the ant moves onto a new pixel it adds the colour of the pixel to its direction and uses the MOD operator to restrict the direction to the range 0-7. There is also some code to keep the ant on-screen.

The initial state requires a series of coloured boxes be drawn on the screen so there is something for the ant to react to. I’ve set up the code to pick random colours for these boxes and for the initial direction the ant travels (its initial position is fixed although it need not be). After this initial setup the ant essentially behaves deterministically.

Here are a set of images from one run of the program.

This slideshow requires JavaScript.

You can see in the first image that the ant has moved in a pretty much structured and predictable way, but as the program runs for longer the ant begins to produce patterns that seem unpredictable and random, notably the longer it runs the more “chaos” is introduced into the image. Because the ant is deterministic you’ll get the same image over time if you use the same initial state, but given any change no matter how small you will end up with a dramatically different image.

I’m no expert in the field of chaos but from what I could glean from the Wikipedia page one of the main attributes of a chaotic system is sensitivity to initial parameters, there are two other attributes, topological mixing and dense periodic orbits but I don’t really understand them. So I think the program may demonstrate chaotic behaviour, but I’m not sure that it’s a particularly good example. In any case it’s certainly fun to watch and play with the initial state.

As a bonus I coded another graphic example that produces a fractal pattern based on triangles. I was told the algorithm by a friend at Uni who had been shown the code when he was young. I’ve reproduced the algorithm here. Fractals are one of those things I’ve been meaning to learn about, but never really seem to get around to. That’s all for today!


0 Responses to “Gwbasic Demonstrates Chaos”

  1. Leave a Comment

Leave a Reply


WordPress.com Logo


Twitter picture


Facebook photo


Google+ photo


Connecting to %s

Blogs I Follow


Mister G Kids


Random Battles: my life long level grind

completing every RPG, ever.

Gough's Tech Zone

Reversing the mindless enslavement of humans by technology.

Retrocosm's Vintage Computing, Tech & Scale RC Blog



retro computing and gaming plus a little more

Retrocomputing with 90's SPARC

21st-Century computing, the hard way



%d bloggers like this: