Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Greetings fellow monks,
I present to you the program that made the fractal on my home node. It was inspired by the C Curve xscreensaver written by Rick Campbell. Right now it's set to generate the same fractal as on my home node, but you can change it around by messing with @Lines and @Points under Settings. $Epsilon is the minimum width/height a line must be to get processed in the next iteration (otherwise, it'd be wasting processing power on lines too small to see, which would be pointless).

#!/usr/bin/perl use warnings; use strict; use Tk; ############ # Settings # ############ my $Epsilon = 6; my $Delay = .5; my @Lines = ([100, 240, 540, 240]); my @Points = map $_/100, ( ( 0, 0), ( 10, 20), ( 90, -20), (100, 0), ); # The expression that generates @Colors looks pretty ugly, but # it's actually the shortest method I could think of for generating # a rainbow in RGB. my @Colors = map sprintf('#%02x%02x%02x', @$_), map [ $_<=256 ? 255 : $_<512 ? 512 - $_ : $_<768 ? 0 : $_<1024 ? 0 : $_<1280 ? $_ - 1024 : 255, $_<256 ? $_ : $_<512 ? 255 : $_<=768 ? 255 : $_<1024 ? 1024 - $_ : $_<1280 ? 0 : 0, $_<256 ? 0 : $_<512 ? 0 : $_<768 ? $_ - 512 : $_<1024 ? 255 : $_<=1280 ? 255 : 1536 - $_, ], (0..1536); ########### # Widgets # ########### my $Main = new Tk::MainWindow; $Main->Label('-textvariable'=>\(my $Status="Initializing..."))->pack; my $Canvas = $Main->Canvas( '-width'=>640, '-height'=>480, '-background'=>'black' )->pack; my @LineItems = map $Canvas->createLine(@$_,'-fill'=>'white'), @Lines; ############# # Main Loop # ############# while (++our $i) { $Status = "Iteration $i..."; my $LinesAffected = 0; my $Color = 0; my $ColorIncrement = (@Colors / @Lines) / (@Points/2 - 1); for (my $Line=0;$Line<=@Lines-1;$Line++) { my @Line = @{$Lines[$Line]}; $Canvas->Exists ? $Canvas->delete($LineItems[$Line]) : exit; my $Size1 = abs($Line[2]-$Line[0]); my $Size2 = abs($Line[3]-$Line[1]); if ($Size1>$Epsilon or $Size2>$Epsilon) { $LinesAffected++; my @NewLines; my @NewItems; for (my $Point=0;$Point<$#Points-1;$Point+=2) { my ($X1, $Y1, $X2, $Y2) = @Line; push @NewLines, my $NewLine = [ $X1+($X2-$X1)*$Points[$Point+0] + ($Y2-$Y1)*$Points[$Point+1], $Y1+($Y2-$Y1)*$Points[$Point+0] - ($X2-$X1)*$Points[$Point+1], $X1+($X2-$X1)*$Points[$Point+2] + ($Y2-$Y1)*$Points[$Point+3], $Y1+($Y2-$Y1)*$Points[$Point+2] - ($X2-$X1)*$Points[$Point+3] ]; push @NewItems, $Canvas->Exists ? $Canvas->createLine( @$NewLine, '-fill' => $Colors[$Color] ) : exit; $Color += $ColorIncrement; } splice(@Lines,$Line,1,@NewLines); splice(@LineItems,$Line,1,@NewItems); $Line += $#NewLines; } else { $LineItems[$Line] = $Canvas->Exists ? $Canvas->createLine( @Line, '-fill' => $Colors[$Color] ) : exit; $Color += $ColorIncrement * (@Points/2 - 1); } $Main->Exists ? $Main->update : exit; } $Main->Exists ? $Main->update : exit; last unless $LinesAffected; select(undef,undef,undef,$Delay); # (A cute idiom for hires sleep) } $Status = "Done."; MainLoop;

For starters, try replacing @Points with one of these sets:

__END__ ( 0, 0), ( 50, 29), ( 50, -29), (100, 0), ( 0, 0), ( 50, 0), ( 50, 50), ( 50, 0), (100, 0), ( 0, 0), ( 30, 0), ( 50, 30), ( 70, 0), (100, 0),

-BronzeWing


In reply to Linear Fractal Generator by BronzeWing

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [1nickt]: You must twist and pull! If you burn, use tea tree oil etc, the tick barfs (inside your blood vessel) and you get all the loevely bacteria in his gut transferred to yours.
    [1nickt]: tweesers work just fine
    [hippo]: Hope everyone else is enjoying their lunch too.
    [1nickt]: However, note that it takes between 2 and 4 hours for a tick to be able to start transmitting bacteria. So even if it has burrowed in and started eating, if you get it soon you should be OK.
    [perldigious]: 1nickt: No more red meat! It would be more humane to just kill you, wouldn't it! :-)
    [1nickt]: Just don't make it barf.
    [1nickt]: perldigious that's exactly what my stepson says.
    [1nickt]: the tick that can make you a vegetarian
    [perldigious]: Your Mother: Yeah, I have a tool for ticks that I use (mostly on my dogs thankfully), but it's just a cheapo one I got from my vets office... it works pretty good though.
    erix saw a tick in a natural history museum collected from the scrotum of the curator (it was removed)

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (14)
    As of 2017-05-24 13:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?