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:
- All cells start with colour (255,255,255) (i.e. white).
- 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.
- 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.
- 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
mathmo
No comments:
Post a Comment