Nice work. To shorten it without obfuscating it, you can remove a lot of repeated calculations. Compare:
sub minkowski { my ($d, $level) = @_ ; if ($level==0) {fd($d); return 1;} minkowski($d/4,$level-1); rt(-90); minkowski($d/4,$level-1); rt( 90); minkowski($d/4,$level-1); rt( 90); minkowski($d/4,$level-1); minkowski($d/4,$level-1); rt(-90); minkowski($d/4,$level-1); rt(-90); minkowski($d/4,$level-1); rt( 90); minkowski($d/4,$level-1); }
Now each calculation done once:
sub minkowski { my ($d, $level) = @_ ; fd($d), return unless $level--; $d /= 4; minkowski($d,$level); rt(-90); minkowski($d,$level); rt( 90); minkowski($d,$level); rt( 90); minkowski($d,$level); minkowski($d,$level); rt(-90); minkowski($d,$level); rt(-90); minkowski($d,$level); rt( 90); minkowski($d,$level); }
That didn't buy much here because the function name is so long. Then, notice how you often have rt($foo); minkowski(@bar); ? You could shorten that by making the angle an optional parameter to the second function.
sub minkowski { my ($d, $level, $rt) = @_ ; rt($rt) if $rt; fd($d), return unless $level--; $d /= 4; minkowski($d,$level); minkowski($d,$level, -90); minkowski($d,$level, 90); minkowski($d,$level, 90); minkowski($d,$level); minkowski($d,$level, -90); minkowski($d,$level, -90); minkowski($d,$level, 90); }
Hmm. We're calling the same function eight times in a row, with only one different parameter. Looks like an unrolled loop, no?
sub minkowski { my ($d, $level, $rt) = @_; rt($rt) if $rt; fd($d), return unless $level--; $d /= 4; minkowski($d, $level, $_) for 0, -90, 90, 90, 0, -90, -90, 90; }

Makeshifts last the longest.


In reply to Re: Fractal Curves: Short & Fast Codes? by Aristotle
in thread Fractal Curves: Short & Fast Codes? by chunlou

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.