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

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...