Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Order Out Of Chaos

by Lysander (Monk)
on Oct 16, 2002 at 00:11 UTC ( [id://205581]=obfuscated: print w/replies, xml ) Need Help??

#!/usr/bin/perl -w use strict; use Tk; my$mw=MainWindow->new;$mw->geometry(#>$(#@) "700x700");my$c1=$mw->Canvas(-background=>#)(*#$ 'black',-height=>700,-width=>700)->pack;my#K(\x23$_ $ax="F_+_F_+_F_+_F";my$rr="F_-_F_+_F_+_F_-_F";#)(*@#(klskld(@#*#() my($phi,$x1,$y1,$x2,$y2,$ll)=(0,185,500,185,500,4);for(my$i=#%z 1;$i<5;$i++){$ax=~s/F/$rr/g;}$ax=~s/\s//g;my@arx=split(/_/,#@++--1 $ax);for(@arx){if($_ eq#$_1f#(!)#Skwio)*# "+"){$phi += 90;if($phi>=360){$phi=$phi-360###@()(*) ;}}elsif($_ eq"-"){$phi-=90;if($phi##map{} <0){$phi=360+$phi;}}if ($_ eq"F"){$x1=$x2;$y1=$y2;if($phi#$#<2*#$ ==0){$x2+=$ll;}elsif($phi==90){$y2 -= $ll;}elsif(#$^%&* $phi==180){$x2-=$ll;}elsif($phi==270){$y2+=$ll;}ml($x1,$y1,#__--0(*()) $x2,$y2);$mw->update;}}$c1->createText(350,350, -text=>"\x50\x20\x45\x20\x52\x20\x4C\x20\x20 \x20\x20\x4D\x20\x4F\x20\x4E\x20\x4B\x20\x53",#*#(()) -fill=>'white',-width=>300);MainLoop;sub#->\x25 ml{$c1->createLine($_[0],$_[1],$_[2],$_[3],-fill=>'white');}

Replies are listed 'Best First'.
Re: Order Out Of Chaos
by diotalevi (Canon) on Oct 16, 2002 at 01:55 UTC

    Oooh! Pretty! That's a fractal right? What's it called?

    use strict; use Tk; my $phi = 0; my $thisX = 185; my $thisY = 500; my $nextX = 185; my $nextY = 500; my $mw = MainWindow->new; $mw->geometry( "700x700" ); my $c1 = $mw->Canvas( -background => 'black', -height => 700, -width => 700) ->pack; use constant PRINT => 'P'; use constant LEFT => '<'; use constant RIGHT => '>'; my $ax = "P>" x 4 . "P"; $ax =~ s/P/P<P>P>P<P/g for 1 .. 4; for (split //, $ax) { if ($_ eq RIGHT) { # rotate right $phi += 90; $phi -= 360 if $phi >= 360; } elsif ($_ eq LEFT) { # rotate left $phi -= 90; $phi += 360 if $phi < 0; } elsif ($_ eq PRINT) { # print $thisX = $nextX; $thisY = $nextY; if ($phi == 0) { $nextX += 4 } elsif ($phi == 90) { $nextY -= 4 } elsif ($phi == 180) { $nextX -= 4 } elsif ($phi == 270) { $nextY += 4 } $c1->createLine( $thisX, $thisY, $nextX, $nextY, -fill => 'white' ); $mw->update; } } $c1->createText( 350, 350, -text => "P E R L \n M O N K S", -fill => 'white', -width => 300); MainLoop;
    __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
      You're right, diotalevi, it is a fractal. Good eyes! Specifically, it's a Lindenmayer system (L-system) type of fractal. A definition of this type of fractal is:

      "A L-system or Lindenmayer system is a formal grammar for generating strings. (That is, it is a collection of rules such as replace X with XYX.) By recursively applying the rules of the L-system to an initial string, a string with fractal structure can be created. Interpreting this string as a set of graphical commands allows the fractal to be displayed. L-systems are very useful for generating realistic plant structures."

      The above definition comes from this FAQ.

      I just recently started reading about fractals, and since this type is string-based, I thought it would be fun to try it out with Perl. The starting shape that I used looked something like this (please excuse the ASCII art):

      ***  ***
        *  *
        ****
      
      Hope this helps, and thanks for the comments.
        So then snowflakes, themselves, are fractals? I always thought that fractals were designs that really had no symmetrical pattern like that, but more random patterns. Cool, I learned something. I like that. Word!
        _____________________________________________________
        mojobozo
        word (wûrd)
        interj. Slang. Used to express approval or an affirmative response to
        something. Sometimes used with up. Source
      Very nice indeed! But, to me, it looks more like a snowflake or tile than a fractal.
      _____________________________________________________
      mojobozo
      word (wûrd)
      interj. Slang. Used to express approval or an affirmative response to
      something. Sometimes used with up. Source

        Try playing with that for 1 .. 4 loop. I really don't know fractals so to my uneducated eye it looks like more detail after more iterations. I pushed it up to 5 but it didn't fit ony my screen anymore.

        __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
Re: Order Out Of Chaos
by Anonymous Monk on Oct 18, 2002 at 23:06 UTC
    check this out

    http://www.iit.edu/~fockjef/lsys

    choose "Custom" for the L-system

    Axiom : F-F-F-F-F

    Angle : 90

    Production
    Rules : F-->F+F-F-F+F

    Try 3 or 4 Generations

    This was done with Perl as well.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://205581]
Approved by sm3g
Front-paged by krisahoch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-16 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found