24
Apr 10

Free Subversion Repository

I have a library of code that I use across all of the projects that I work on. I also work across several computers so I thought that it would be handy to have my library in a subversion repository so that I can update and synchronise my library from anywhere. After checking out a few options I signed up with Springloops. They offer a free service with 100MB storage and up to three projects. This is perfect for personal use and so far it’s been working really well. That’s a recommendation from me then!

03
Apr 10

Conway’s Game of Life Using a Convolution Filter

This is a repost from an old blog I used to have. I’ve cleaned up the code a bit but the idea remains the same.

Conway’s Game of Life is an example of a cellular automaton. It is based on a square grid of cells who live or die depending on now many live neighbouring cells they have. The obvious way to code this would be to have a two-dimensional array storing the state of each cell and then going through each cell to calculate its new state.

Ugh, boring.

It would be much more fun to use a convolution filter to determine if a cell should live or die. Convolution filters take an array of values (called a kernel) which it treats as a two-dimensional grid whose values determine the colour of a pixel based on the pixels around it. All that’s needed after that is a palette map to set the variously coloured pixels to their correct alive or dead colours.

Certain starting shapes produce very complex outcomes when the rules are repeatedly applied to the grid. When you click on any of the running demos, a shape called “the Acorn” will be drawn at the mouse position and the state of the grid will be updated every frame.

The actionscript source code for this first example is at the end of the post. Click on the image to play the demo of Conway’s Game of Life:

Simple Conway's Game of Life

This is a more refined version where dead pixels are cycled through a palette of decay colours:

Conway's Game of Life with decay

This is a happy accident I ended up with when I was working out the fastest way of applying the palette of decay colours

Conway's Game of Life gone wrong

Actionscript source code for the first example is available below:
More…

01
Apr 10

Truncating Text

Here’s a code snippet that takes a textfield and checks to see if its text is too long to fit in the textfield. If it is, it truncates the text and adds an ellipsis (that’s three dots to you) to indicate that the text has been truncated.

function truncateText(textField:TextField):void {
    var text:String = textField.text;
    while (textField.maxScrollV > textField.scrollV) {
        text = text.substring(0, text.length - 1);
        textField.text = text + "...";
    }
}
Copyright © 2012 The Daily Flash
Proudly powered by WordPress, Free WordPress Themes, and Linux Hosting