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

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