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;
See 70931 for a method by Dr.Mu which is slower but saveable -> it doesn't use rectangles as pixels.


In reply to Sierpinski's Triangle - Tk by bl0rf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.