Randomized smooth curves

I was skimming through Keith Peters “Making Things Move” for AS2, and i stumbled upon a section about how to draw multiple smooth curves to form one smooth line. This has always puzzled me, so I decided to try it out, and i found that it’s a lot easier than I thought.

 The idea is to pick some random points, at least 3, if you want to form a contiguous shape, and find their midpoints. Then use the midpoints as anchor points for the curveTo method and the randomized points as controlpoints.

Smooth curves

Above image is an illustration of the concept. Blue dots are the randomized points. Black dots are the midpoints. Black line are the curves drawn with black dots as anchor points and blue dots as control points.

And thats it! Very simple indeed. I’ve made a little app that demonstrates the concept. Check it out here. Drag the blues markers to change shape. Figure out what the buttons do yourself! :)

Langton’s Ant

Just finished my rough cut of an implementation of Langton’s Ant. It is a so called turning machine, invented by Chris Langton in 1986.

The application consist of a grid containing all white squares, and the “ant” which is just a reference to the current position on the board (marked with a red square). For every step of the iteration, the ant follows these two simple rules:

  • If the ant is on a white square, turn 90° left, paint the square black and move forward one tile
  • If the ant is on a black square, turn 90° right, paint the square white and move forward one tile

This, in spite of the very simple rule-set, results in some quite complex patterns, and at a certain point the ant starts building a “highway”, which is about 100 continuously repeated steps, forming a track in the southwestern direction.

Here are some snapshots of the grid after a certain number of iterations

100 iterations
Langton’s Ant - 100 steps

1000 iterations
Langton’s Ant - 1000 steps

10000 iterations
Langton’s Ant - 10000 steps

Aaand, we have a highway! (about 13000 iterations)
Langton’s Ant - The highway has been built

 See for yourself here (be patient, it might take a moment to load).

Source code can be found here (Flex Builder 2 archive file).

PS. The simulation tends to run faster if you move your cursor outside the SWF area, and to be honest, I have no idea why!?