http://www.perlmonks.org?node_id=337175

I've had lots of fun making this one, and its pretty cool. It all started three days ago when I took out a book from the library:
M.Field and M.Golubitsky, Symmetry in Chaos, 1992: Oxford Press.
I suggest that you read it, it explains how to use chaos/fractals to create symmetric images ( very beautiful ). After reading the explanation about fractals I decided to finally wrestle with Tk and make a fractal.

```#!/usr/bin/perl
## Sierpinski's Triangle ##
use Tk;

\$width = 800;
\$height = 500;
my \$main = MainWindow->new();
my \$canvas = \$main->Canvas( -width=>\$width, -height=>\$height, -backgro
+und=>"black");
\$canvas->pack( -expand=>1,-fill=>'both' );

# the coderefs take ( x, y )

@iterative_set = (

sub{ my @pt = (400,50); return(  (\$pt[0] + \$_[0] )/2,
( \$pt[1] + \$_[1] )/2 ) },
sub{ my @pt = (50,400); return(  (\$pt[0] + \$_[0] )/2,
( \$pt[1] + \$_[1] )/2 ) },
sub{ my @pt = (750,400); return(  (\$pt[0] + \$_[0] )/2,
( \$pt[1] + \$_[1] )/2 ) },

);

# start coordinates
\$x = 40;
\$y = 400;
\$iter = 0;

# weed out transients
while( \$iter++ != 100 )
{

( \$x, \$y ) = \$iterative_set[ int rand 3 ]->( \$x, \$y );

}

\$iter = 0;
while( \$iter++ < 10000 )
{

( \$x, \$y ) = \$iterative_set[ int rand 3 ]->( \$x, \$y );
\$canvas->createRectangle(
int \$x, int \$y, int \$x, int \$y, -outline=>undef, -fill=>'white' );

}

MainLoop;