Wednesday, September 2, 2009

fractal pinwheels

These are some little pinwheels made by a little fractal line drawing + you typical draw lines around a circle code:



You can see it in action here. Click anywhere to draw a random pinwheel... and hit space key to clear them

Here is the function to draw the lines:

public function funky_line( g:Graphics, x1:Float, y1:Float, x2:Float, y2:Float, depth:Int, max:Int ) {
if ( depth > max ) {
g.moveTo( x1, y1 );
g.lineTo( x2, y2 );
} else {
depth++;
var nx = -1 * ( y2 - y1 ) * ( depth / ( depth * depth ) );
var ny = 1 * ( x2 - x1 ) * ( depth / ( depth * depth ) );
var xm = x1 + ( x2 - x1 ) / 2 + nx;
var ym = y1 + ( y2 - y1 ) / 2 + ny;
funky_line( g, x1, y1, xm, ym, depth, max );
funky_line( g, xm, ym, x2, y2, depth, max );
}
}


Max is the number of recursions and count is the number of lines to draw around the circle...

Neato...