in reply to Fractal Curves: Short & Fast Codes?

I'm pretty amazed by what you did - I just love the idea and the code seems just fine. However, being a newbie, I'm not really good at making it work.
I first installed the GD package I didn't have. But the code still isn't working fine. They are 2 lines which I don't understand :
        $xy->[0][scalar(@{$xy->[0]})] = $d*sin(PI*$h/180) + $xy->[0][$
+#{@{$xy->[0]}}];
        $xy->[1][scalar(@{$xy->[1]})] = $d*cos(PI*$h/180) + $xy->[1][$
+#{@{$xy->[1]}}]; 
Could you please explain them ? They appear in the first 2 scripts.
In the last one, what is plotxy ? It's not defined anywhere... Is it part of GD ? (I tried GD::plotxy but it still didn't work :( ).
Please let me know what I'm doing wrong - I'm currently using WinNT with ActivePerl.
  • Comment on Re: Fractal Curves: Short & Fast Codes?

Replies are listed 'Best First'.
Re: Re: Fractal Curves: Short & Fast Codes?
by chunlou (Curate) on Jun 17, 2003 at 11:45 UTC
    No, I defined plotxy() in the code; it isn't part of GD. I only included it in Closure, omitted elsewhere since it's redundant to include it three times in the post.

    As for the two lines...

    If $xy = [[4,5,6],[4,5,6]], scalar(@{$xy->[0]}) = scalar(@{$xy->[0]}) = 3, the number of elements.

    $xy->[0] points to the first array in $xy; $xy->[1] second.

    @{$xy->[0]} dereferences $xy->[0] into an array.

    So, $xy->[0][scalar(@{$xy->[0]})] will be like $xy->[0][3], the new element in the array, yet to be defined, since the index of the last position is 2.

    $d*sin(PI*$h/180) is just some transformation stuff from trigonometry/geometry/calculus.

    $#{@{$xy->[0]}} gives you the index of the last element, which is 2 in this example.

    So, $xy->[0][$#{@{$xy->[0]}}] = $xy->[0][$#{@{$xy->[1]}}] gives you 6.

    (I've noticed you have "...$+#..." in your reply. When you see + in a code in the post, it indicates a continuation from the previous line. When you cut and past codes, those + might be inadvertently included. Remember to remove them.)

    Hence, the two lines basically say,

    new x coordinate = distance (on x axis) from old x coordinate + old x coordinate
    new y coordinate = distance (on y axis) from old y coordinate + old y coordinate

Re: Re: Fractal Curves: Short & Fast Codes?
by fglock (Vicar) on Jun 17, 2003 at 12:36 UTC

    You can get rid of the "+" by using the "d/l code" link:

    comment on Fractal Curves: Short & Fast Codes? ---> d/l code <---