Saturday, 13 October 2012

Blurring the truth, because lies tend to be prettier

I have been playing with my new RGB ants and this is my favourite image so far:


Apparently computerized ants bring out the arts student in me

I do though have to admit that I have rather cheated with this image. This is not pure output from the ants. When running my new code I quickly realised that the ants had a tendency to get into a temporary loop where they ran over a subset of cells for a period of time. This meant that the colour of these cells was very stark compared to the general blending which otherwise occurred. I solved this by applying a blender which compared each cell to its neighbours and if their difference was greater than some user-defined blur constant then it averaged the colour of the two cells and set both to that average. The blurring runs again and again until it carries out no more averaging. I have created a GIF to illustrate what effect this has:


At least it's a well blended murky grey...

As you can see, the blurring works but also tends to make the colour darker. I have listed the help of some computer scientists, and I will hopefully have a better blurring algorithm sorted out fairly soon. On the other hand the blurring tool has given me some ideas for other tools, like something to brighten up the image by adding a number to each RGB value of every cell or a contraster which increases the difference between coloured and non-coloured cells.

589793,

mathmo

Sunday, 7 October 2012

Colours, colours everywhere; but not a drop of mink (153, 138, 119)

<Token apology>It has been a ridiculously long time since I last posted, but university.<\Token apology>

This post is a kind of confession, a confession that I am fairly idiotic. One of my friends at university was looking at this blog and noticed that when I was writing the 'colouring-in' code that I had my ants overwriting each other, i.e. that if a blue ant landed on a square which a green ant had last been to you would get blue. The conversation went something like:


"Y'know how <see above>, why did you write it to do that?"

"It was the only way I could think of to implement some sort of RGB colour scheme."
"Why don't you just get the ants to subtract one from the respective RGB colour of the cell they land on?"
"..." *I am so stealing that idea.*

I didn't explain it well above, but essentially RGB (RedGreenBlue) is a way of defining colour using triples (R,G,B) where 0  ≤ R,G,B ≤ 255. The size of the number determines how light or dark the contribution of that colour to the overall colour is. For example (0,0,0) is black, (255,255,255) is white and the colour of human flesh  is (255,125,64). Honestly, I'm not making this shit up.


I have now written the code for this, with the following premise:



  1. All cells start with colour (255,255,255) (i.e. white).
  2. When an ant lands on a cell the program sums the RGB values of that cell and if the number is even it turns left and if it is odd it turns right.
  3. The colour of the cell changes by one in the respective colour, e.g. a blue ant would subtract one from the last number and a cyan ant would subtract one from the second and third colours.
  4. If an ant encounters a wall it is moved one space backward and its direction randomly chosen. (I have kept the ability to make any shape of container for that ants.)
I have only played with this for a few minutes, but I thought I would share one of the initial images:


14159,

mathmo

Thursday, 23 August 2012

Is this a blog post that I see before me?

This is a quick blog to share some awesome with you. I have spent the afternoon playing with my new macro, and have acquired a rather compulsive attitude towards 8-bit images.

Using Langton's Ants on Excel! Hmm, maybe it won't catch on.

Ah hem. You can expect the next few blog's to completely consist of 8-bit images I have stolen from the internet and coloured in using ants. And in case you have just joined the blog I am not pulverising a colony of ants from my back garden then using the resulting paste to defile a children's colouring-in book. They are digital ants. Which makes it okay. I think, I am yet to check this with the RSPCA. And so on to the images:


Do you get +1/2 life if you eat the first one?

It was when I was making the mushroom that I realised it would be much easier if I could use the same mechanism to colour in the edges as I do for selecting the colour of ants and adding the highlights. I also added the ability to make 'white' ants, which I needed for the face of the mushroom.


Pretty freakin' awesome

I got the pattern for this one off a blog. This is the coolest thing yet to come out of this project by a rather embarrassing amount. I have noticed a trend in my blog posts in that I very nearly never come back and do anything that I have put in a list. It is very probable that this list will suffer the same fate. This is a list of things I want to 8-bitanterize:

  • A world map. Mercator's projection naturally, although I could be persuaded to go Gnomonic.
  • Harry Potter.
  • A famous painting.
  • A random picture off of Facebook.

Those are in order of do-able but time consuming to impossible but I'll bloody well kill myself trying.

4159,

mathmo

Wednesday, 22 August 2012

Pikachu and Puns

"Hello project, it's been a while. I am sorry I haven't called (your macro) recently but things were getting a little intense and I needed a break; some time to play around with other programming languages y'know? There was this one I knew from university and things were going really great for a while. Then it started harping on about my soul and 'happiness', a little too religious for my liking. Anyway I am back for good now. mathmo"
Perhaps a little weird and probably highly confusing. There is a joke in there for the CompSci's, there is a joke in there for the Mathmo's, and there is a lot of confusion over the nature of my relationship with my computer for the rest of you. To put you at ease the above translates as "I have had to put my project aside for the last couple weeks to do university work, consisting of maths and programming in MatLab".

Moving swiftly onwards...

Pikachu, now with surprisingly small feet

Now, pick wisely:

  • If you came here solely for a brightly coloured picture of Pikachu, I recommend you now head here.
  • If you came here for an 8-bit technicolour image of Pikachu coloured in by 10 binary ants, keep scrolling.

At first this image seems like a fairly simple output. Just draw a black outline in Excel, then tell it what colour you want each section to be, and where you want each ant to start, and then you might as well tell it to put in highlights like the white's in Pikachu's eyes. Right. Simple.

I think my solution was pretty elegant; in my final version to get the above output you only needed to input:


Painting by letters, does this count as algebra?

Each lower-case letter is the starting point of an ant that has the colour indicated by the letter. Upper-case letters are the highlights, those colours are added on top of the ants' paths at the end of the computation. For instance the "y" indicates that a yellow ant should start from this position, and the "A" indicates that this cell should be coloured white at the end. I have also covered the possibility of you wanting to stack these, for example "yA" would be translated as "I want an ant with a yellow ant to start here and for this cell to be coloured white at the end". I have only included the primary and secondary hex colours (red, blue, green, yellow, pink, cyan) so far. The code for each colour is the first letter of the name of the colour; except for black and white, where black is "z" and white is "a". Damn you blue.

I also included the option for the user to alter the gradient of the colour. For example setting the gradient at 50 produced the block colours above, but setting it at 1 would give:


Nintendo came to regret zombie Pikachu

For this particular image the lower gradient doesn't really work, but sometimes it is quite a nice effect:


My next blog post will have many Pokeballs

In terms of the structure of the program I had to come up with a completely new set up. I completely scrapped the system where I stored the location of each ant each turn and then when it came to displaying only changing the colours where an ant stepped. Now each cell has a 'hit' counter, incrementing each time an ant lands on it and making the ant turn right if the counter is even and left if it is odd, as well as a variable which 'remembers' the colour of the last ant to land on that cell. The colours are only added when the result is outputted.

653,

mathmo

Wednesday, 18 July 2012

Colouring in: bored-student-in-the-early-hours-of-the-morning style

You remember the fun of colouring in don't you? A sheet of paper printed with some monochrome pattern was given to you by your parents to keep you quiet for a couple hours. You steadily coloured in each block with care and attention, pretending each one filled in was another area of Metropolis that had fallen to the pandemic... Oh, that was just me? Perhaps that goes some way to explaining why I am the sort of person who writes a programming blog at 3am.

Seeing as I am writing this at 3am I really should write about something. It would appear that I have written a very good introduction to a post about colouring in, which is particularly fortuitous as I have a very good program to write about that does exactly that.

What I have done is altered my last program so that instead of using a square box it uses any user inputted shape. To input a shape you first need to create a boundary of black cells, ensuring that it is closed, i.e. every black cell is touching at least two others horizontally, vertically or diagonally. You then need to set a spawn point by entering any characters in any one cell in the centre of your shape. In this rendition every ant is spawned at one cell for simplicity. So suppose I entered this:

A heart turns out to be an easy bit image.
Here the '<3' is my spawn point. If I then run my code with one ant it produces this:


The only thing cuter would be a kitten. I am not doing a kitten.

I am going to admit that it took me several runs to get this because the colours are still on random, but my romantic side refused to have anything put a red heart. Alright, pink. I'm not quite romantic enough to spend 30 minutes of non-sleeping for my computer to happen to pick brilliant crimson out of the sixteen million possible colours allowed by my code.

31,

mathmo

Thursday, 12 July 2012

Art for maths sake


gif maker
Sampling every 100, 50, 25, 10, 5, 1 steps.

This is the explanation for the images:
"First order of business was to fix my program from last post. Obviously the 22.8GB variable had to go. I managed to replace it with two 20KB variables, but in exchange for  that I have to spend a lot longer outputting. As per usual the program runs the entire simulation before outputting anything. When it gets to the visual output stage I have a counter which goes from 2 to 100000 with a step size of n. Every time the counter increments I change the colour of the cell that the ant is currently in to the colour it is meant to be at that turn according to the pre-processed simulation. That means that to get the full output I had to use a step size of 1, which is particularly processor-intensive but works. I then thought to myself "what would happen if I didn't use a step size of 1?". That resulted in the images above."
 I quite like the variety of styles in the images above, in particular:
  • The sparsity of the 100-step image.
  • The polka-dot of the 10-step image.
  • The suspiciously like a colour-coded topological map 1-step image. (I wonder if I could alter Langton's Ant to produce a randomly generated landscape...)
If you have an opinion please comment below, I want to pursue these further and it would be great to have some idea of what looks best!

Oh and seeing as someone managed to solve my last number pattern (it was the differences of consecutive 5th powers) I have come up with a new one!

3,

mathmo

P.S. This is a bloody difficult one, I will be impressed if someone gets it!

Sunday, 8 July 2012

My computer can't quite remember that much

I was planning to have a new post for you tonight, but some exceedingly bad programming on my part has scuppered that plan. More on that in a minute.

I have written a program that, if it was run on say your average supercomputer, would run very similarly to my initial multiple ant program except with a twist. When an ant lands on a coloured cell the cell won't revert to being white, it will instead turn a darker shade of the colour it currently is. To ensure this doesn't result in ants going in circles I have written it so that the cell alternates between being classed as 'coloured' or 'white' in the classical Langton's Ant sense.

I came up with this particular idea on a bus journey a couple days ago, when I realised that some of the patterns that have been cropping up are in their own way quite beautiful. I think this new iteration will result in some spectacular images.

A quick update on the developing maturity of my code:

  • I have rediscovered For...Next loops. I am now saving about 5 minutes on each bit of code, as I don't need to go back at the end and find the counter=counter+1 that I have missed out. For...Next loops work by taking a number equal to some specified lower bound, running a piece of code with that number and then incrementing the number until the number equals some specified upper bound. Do While loops take a number and keep running the code while the number meets some condition, say being less than or equal to some specified upper bound. So they are virtually the same, except in a Do While loop you need to manually increment the number each time the code runs, which is a little bit tiresome when you have twenty of them.
  • I have moved all of my colours into Hex, meaning I can get a much bigger range of colours. Read bigger as 300,000 times bigger.


And now finally we get to the reason I don't have anything juicy for you tonight...

The code I wrote tried to create a 22.8GB variable. Yes, a variable nearly 4 times larger than Skyrim. AND it was trying to create it in RAM. The thing is, I know exactly how to get around this as I did it that way in all of my previous code. I just happened to try something new and it has backfired spectacularly. The error was so big that instead of bringing up a basic error message Windows took control, fired off an error report to whomever those actually go to and restarted Excel. That has never happened to me before.

I will sort this all out tomorrow, by which time my computer will either have calmed down or comitted itself.

4651,

mathmo


Sunday, 1 July 2012

Football, football, chimpanzee-riding-a-segway, football

I have finished my challenge! With ten minutes remaining until I go to the pub, I have typed the last of my 200~ lines of code... I don't have time to upload it, but tomorrow I will be uploading a GIF of the game in action. Come on Italy!

Update:

Admittedly this IS rather later than planned, but it turns out I was being pretty optimistic when I said I was 'finished'. Fifty-additional-lines-of-code optimistic; including a timer, a visual output and a complete re-haul of what I am naively calling my 'engine'. Note: the ball is the black dot that spends most of the game flashing into and out of existence, and when it is in existence thinking "Oh, this patch of grass again".


I apologise for the points where the entire board goes blank, that is when the moment that the screen recorder takes an image syncs up with when I clear the board before placing the ants at their next position. As you see in the message box at the end the game was a nil-nil draw, and that was with 51 players on each side. Clearly there is no need to replace Manchester United with giant robotic ants. Yet.

My game has some simplified rules:

  1. Players start randomly positioned around their own half.
  2. The goalies are only only allowed to move up and down their goal line (orange).
  3. When a player runs into the ball it is kicked in a straight line of length ranging between 10 and 30 cells. The ball stops if it hits another player.
  4. If the ball goes out the sides it is randomly positioned on a line parallel to the halfway line.
  5. If the ball goes out the ends it returns to the centre (a weak simulation of a goalkick).

For interested parties, here is the entire spreadsheet of my project. For the football program go to the "Football" sheet, then CTRL+E to bring up the menu and type in "football".

Technical details:
The way I have written this program is such that it processes the entire game before putting up the display. The benefits of this are a smoother visualisation and the ability to remove the 'trail' of the ant making the visual output much clearer. This means I am now not storing the locations of my ants in excel cells, but in 2 three dimensional arrays (three because I reference by player number, by team number and by turn). This is much more memory heavy, but gives the benefits listed above.

2101,

mathmo

Easter Egg 1: A chimpanzee riding a Segway.

Easter Egg 2: In the spreadsheet go to the sheet called "Game", CTRL+E to bring up the menu and type in "game2". Be amazed. WARNING: This uses my old style of processing so will take a while.

Thursday, 28 June 2012

Pre-game warm-up (Updated to include "Is this code I see before me?")

I have some bad news and I have some good news. Before I am hunted down by a ravenous horde of arts students, please note that:
  1. I apologise for the cliché. 
  2. I apologise for the cliché of starting a post with a cliché.
  3. I apologise for the cliché of apologising for using a cliché. 
Now that I have finished cliché-ing my clichéd cliché's, let's move on to the news.

The bad news is that I have no pretty pictures (note the alliteration, I really am trying arts students) for you today as my computer has overheated. Or in other words my laptop has decided that what it would really really like to do instead of running my program is to raise the mean temperature of the local area by a couple degrees then take a half hour siesta. And by local area I mean Scotland. The good news is that I have written the program that should have produced said pictures, and I will be updating this post tomorrow assuming that the heat has dissipated sufficiently. I suggest you read "dissipated sufficiently" as melted the polar ice caps.

If you can read between the lines or italics, I have been a little antagonized by my laptop this evening. I think part of my problem is also that my code is extremely inefficient, mostly down to the constraints of using excel cells, something which I am going to need to deal with as this project progresses.

Here is a brief summary of the code my computer tried and failed to run:
Multiple ants are contained within a nxn square which has a boundary which the ants bounce off of. When one ant lands on another, the second ant "kills" the first. The game runs until only one ant is left alive.
It looks simple enough, but it quickly becomes clear that this is a game that will last a LONG time. Imagine you have only two ants on a 10x10 board. Suppose the ants are randomly placed each turn (uniformly for the probability nerds), then the probability of one ant killing the other on any one turn is 1/100. It is fair to say  that the odds are actually worse than this, as the position of the ant at every turn is determined once the ant is placed on the grid and these positions are likely to be fairly far away from the other ant on most turns. But suppose it is 1/100. Then if we scale to a 100x100 board (tiny on spreadsheet sizes) the odds are 1/10000. If we then introduce another ant being randomly distributed around the board the odds go up to 1/3333. Now suppose we use the entire spreadsheet and all 54 ants. Then we have odds of 1/6002750 that an ant will be killed on any one turn. And that is just the first ant. All in, the odds of there being a winner is approximately 1/10^426. For a sense of scale, excel returns that number as zero. 10^426 is 25 orders of magnitude larger than the age of the universe in seconds, or 5 orders of magnitude larger than the number of protons in the observable universe.

I have been extremely vague in my probabilities, but I think you get the picture. This game was an interesting diversion, but I will need to adapt it to actually make it completable. So far my best idea to correct this has been some form of area kills. However I am going to put this on hold for a new game. Ladies and gentleman I am going to issue myself with a challenge; to design and create a football game involving Langton's Ant by the full time whistle of the Euro 2012 Final.

781,

mathmo

Update:

I managed to run my code tonight, and it turns out that it wasn't so much my laptop overheating as that I had inadvertently included an infinite loop. "Sorry laptop, I will take you out for a byte to eat to make up for it."

The Game
I had to alter the game quite a lot to make it finish-able, but even then I had to limit it to running each ant 100,000 times then declare all surviving ants as winners. I have also managed to solve my previous issue of limited space by making the black border transport ants to the order side of the board. This can be most easily seen in the Cyan ant, where its expansion is divided by the border but is still continuous. You can also see that the Cyan ant has eliminated the Light Green ant fairly quickly. Other highlights include the epic battle between Maroon and Pink, and the swashbuckling adventures of Dark Blue, who seemed to be duelling 6 opposing ants at once. Pink wins the award for being the only ant to reach all four sides.

I think I can do more with this game, such as making it team battles and giving each ant lives and a special ability (for example extra speed or area attack), but I am putting it aside for now to focus on my challenge.

Interesting factoid: One of the errors that cropped up during coding was that I had forgotten to move the 'corpses' of the dead ants off the board. This resulted in ants claiming multiple kills for in essence what was them jumping up and down on a dead body. Who said programming wasn't gory?

Wednesday, 27 June 2012

The Execution (preferably of my code not of me)

Since the main audience for this will be people interested in programming, I think it is about time that I uploaded my code!


Sub antmenu()
'This is the code for the menu. It loops until a valid command is entered, in which case it runs that program then returns to the menu.
Dim mode, menucounter As String


menucounter = 0


Do While menucounter = 0


    mode = InputBox("Which program would you like to run?")


    Select Case mode
        Case Is = "demo"
            demo
        Case Is = "advanced"
            advanced
        Case Is = "clear"
            clear
        Case Is = "exit"
            menucounter = 1
        Case Else
            MsgBox ("Invalid option")
    End Select
Loop


End Sub


Sub demo()


Dim xa, xb, ya, yb, directiona, directionb, coloura, colourb, turn, offsetx, offsety As Long


xa = 8192
ya = 524288
turn = 1
offsetx = 100
offsety = 100
directiona = 4
directionb = 2
xb = xa + offsetx
yb = ya + offsety


Do Until turn = 50000
    
    coloura = Cells(ya, xa).Interior.ColorIndex
    If coloura = -4142 Then
        directiona = directiona + 1
        Cells(ya, xa).Interior.ColorIndex = 3
    ElseIf coloura = 1 Or 29 Or 5 Or 3 Or 12 Then
        directiona = directiona - 1
        Cells(ya, xa).Interior.ColorIndex = -4142
    End If
    
    If directiona = 0 Then directiona = 4
    If directiona = 5 Then directiona = 1
    
    Select Case directiona
        Case Is = 1
            ya = ya - 1
        Case Is = 2
            xa = xa + 1
        Case Is = 3
            ya = ya + 1
        Case Is = 4
            xa = xa - 1
    End Select


    colourb = Cells(yb, xb).Interior.ColorIndex
    If colourb = -4142 Then
        directionb = directionb + 1
        Cells(yb, xb).Interior.ColorIndex = 12
    ElseIf colourb = 1 Or 29 Or 5 Or 3 Or 12 Then
        directionb = directionb - 1
        Cells(yb, xb).Interior.ColorIndex = -4142
    End If
    
    If directionb = 0 Then directionb = 4
    If directionb = 5 Then directionb = 1
    
    Select Case directionb
        Case Is = 1
            yb = yb - 1
        Case Is = 2
            xb = xb + 1
        Case Is = 3
            yb = yb + 1
        Case Is = 4
            xb = xb - 1
    End Select


    turn = turn + 1


Loop


End Sub


Sub clear()
Range("A1:XFD1048576").Interior.ColorIndex = -4142
Range("A1:XFD1048576") = ""
End Sub




Sub advanced()


'Asks the user the number of ants they want.
Dim n As Integer
n = 55
Do Until n < 55
    n = InputBox("How many ants would you like?")
    n = n - 1
Loop


'Creates the arrays, x and y are the coordinates and currentcolour the colour of the cell the ant is in. Colour is the colour and direction is the direction of the ant, and turn is fairly obvious.
Dim x() As Long, y() As Long, direction() As Long, currentcolour() As Long, colour() As Long, turn As Long
ReDim x(0 To n) As Long
ReDim y(0 To n) As Long
ReDim direction(0 To n) As Long
ReDim currentcolour(0 To n) As Long
ReDim colour(0 To n) As Long


'Sets up the intial positions of the ants, randomly placing them around a 200 cell square.
x(0) = 8192
y(0) = 524288
direction(0) = 1
colour(0) = 3
turn = 1
Dim counterinitialpositions As Integer
counterinitialpositions = 1
Do Until counterinitialpositions = n + 1
    x(counterinitialpositions) = x(0) + Int((201) * Rnd - 100)
    y(counterinitialpositions) = y(0) + Int((201) * Rnd - 100)
    direction(counterinitialpositions) = Int((4 - 1) * Rnd - 1)
    colour(counterinitialpositions) = 3 + counterinitialpositions
    counterinitialpositions = counterinitialpositions + 1
Loop


Dim counterruntime As Integer


Do Until turn = 50000
    counterruntime = 0
    Do Until counterruntime = n + 1
        
        'Changes the colour of the cell and direction of the ant.
        currentcolour(counterruntime) = Cells(y(counterruntime), x(counterruntime)).Interior.ColorIndex
        If currentcolour(counterruntime) = -4142 Then
            direction(counterruntime) = direction(counterruntime) + 1
            Cells(y(counterruntime), x(counterruntime)).Interior.ColorIndex = colour(counterruntime)
        Else
            direction(counterruntime) = direction(counterruntime) - 1
            Cells(y(counterruntime), x(counterruntime)).Interior.ColorIndex = -4142
        End If
        
        'Keeps the direction modulus 4.
        If direction(counterruntime) = 0 Then direction(counterruntime) = 4
        If direction(counterruntime) = 5 Then direction(counterruntime) = 1
        
        'Moves the ant.
        Select Case direction(counterruntime)
            Case Is = 1
                y(counterruntime) = y(counterruntime) - 1
            Case Is = 2
                x(counterruntime) = x(counterruntime) + 1
            Case Is = 3
                y(counterruntime) = y(counterruntime) + 1
            Case Is = 4
                x(counterruntime) = x(counterruntime) - 1
        End Select
        
        counterruntime = counterruntime + 1
    Loop
    turn = turn + 1
Loop
End Sub

The code is in green and the comments are in red (comments are just notes that describe what the following section of code does). I decided not to waste time making the demo readable, if you read through the advanced code you should be able to see fairly easily what the demo is up to.

If you want to try this code out for yourself then you will need to do the following:
  1. Open up Excel (hopefully you are using 2007/10, if not then just comment and I will give you help), go to the 'view' tab and click on 'macro' on the far right.
  2. Click 'create' in the small window that opens, then copy and paste the code into the new window.
  3. Close both new windows, then Ctrl+E will bring up the menu. 
  4. The four commands are 
    1. "basic" - Runs two Langton's Ants in the same starting pattern as in my first post.
    2. "advanced" - Runs n ants, randomly distributing them around a 200 cell square.
    3. "clear" - Returns every cell to its default white.
    4. "exit" - Closes the menu.
No updates on the code today, but I am going out to the pub during the day tomorrow leaving all evening for some drunken antics (I apologise, I really couldn't help myself).

211,

mathmo

Tuesday, 26 June 2012

2 to 54, but is n possible?

After an hour's work I have amended my program so that it supports up to 54 ants running at once. Not quite n, but that is the largest number of colours I can easily use in excel cells. There is probably something I can knock together using hex but I will look at that tomorrow. Or perhaps some sort of alternating colours? I might try it even if I do figure out hex, because who can resist a wild spotted ant?

So my maiden use of my new 54-ant toy was with 3 ants, which turned out to be pretty unspectacular as the ants were so spread out they didn't even interact. So I reduced the size of the spawn area, cranked up the number of turns, and for good measure tried it with ten ants. Below is the result.
Ten ants running at once.
Just this one quick run has already thrown up a lot of interesting ideas. 
  1. Cyan and Light Green collided at the very start of the run in such a way so that they followed the other ones path back to the starting position, ERASING the path as they went. Fortunately by the time they had regrown Blue had gotten in the way or we might have been stuck in an infinite loop.
  2. It is possible for ants to hijack other ants highways, moving in an almost straight line along it. My first observation of this was Light Green climbing Red's, coming back down the other side and in the process forcing red to create a second highway back into the spawn area.  
  3. Several times ants were in the right direction and cell such that they got caught following another ants path. This occurred with the Olive ant erasing most of Light Blue despite the fact that Light Blue's path was interleaved with Dark Blue.
  4. Pink just sat back and watched the carnage. We can see the distinctive shape of an unmolested Langton's Ant, a clear indicator that despite the bizarre goings on that our code in fact runs correctly.
I think that tomorrow I will try to increase the number of ants I can have, find a way to highlight the position of each actual ant and to create an optional elastic barrier around the edge of the spawn zone.

31,

mathmo

Introductions

Okay, I am writing this first post at what I had originally planned to be the end of the project, but today I revised that decision. 

To get you up to speed: I have some basic functionality with a central menu that calls the demo as well as the clear option. The demo is two of Langton's Ants separated 100 cells each way and going in opposite directions. I have found that this set up was the simplest demonstration of the possibilities that multiple ants offer. (The clear option simply sets every cell on the spreadsheet to blank.)

Demo option produces this simple collision.
Demo option produces this simple collision.

This afternoon I decided to see what would happen if I ran the demo multiple times without clearing the sheet. The result was beautiful.

The result of the demo being run 8 times in a row.
At first the two ants were in perfect symmetry, but eventually they moved into a square at the same time. The way I had written this code was that the red ant progressed on each turn before the green ant, hence when they 'collided' they were thrown out of symmetry as expected. But what happened next was most definitely unexpected. The two 'knots' formed where the highways intersect are perfectly symmetric, but occurred AFTER the break in symmetry at approximately the same time for both ants.

I think this is rather a case of
"Now this is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning." - Winston Churchill
I now plan to expand and improve my macro, on my wish list so far are:

  • A border so that each ant terminates when it reaches the edge of the screen.
  • An option for the user to have as many ants as they like.
  • 'Passive' and 'Aggressive' modes, where ants annihilate any ants they 'land' on.
  • Separate the macro into its own program. (Don't hold your breath on this one.)
I won't upload my code yet as there is always the risk that one of you might actually have access to a velociraptor.

1,

mathmo

About Me

I am a mathmo (mathematician for anyone not familiar with Cambridge slang) studying at the University of Cambridge, and this is the blog of my summer project on Langton's Ant. This project was dreamt up one evening in the college bar when I was showing some of the compscis (computer scientists) my old visual basic excel macros and stumbled across a very basic Langton's Ant. What I showed them was just one boring black ant. By the time I left the bar that morning I had progressed to two coloured ants colliding with each other, the demo macro that most of this project is built from. Through this project I hope to expand my knowledge of visual basic, encourage others to mess around with maths on their computers, and to make a lot of pretty pictures. I will aim to keep my language fairly non-technical, but feel free to comment if you have a question or even a suggestion on how to improve my code. Here it goes...