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

No comments:

Post a Comment

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