Keep It Simple, Stupid PerlMonks

### comment on

 Need Help??
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":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-05-20 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found