[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Odp: LOGO-L> Sierpinski Curves]




Frank wrote:
<snip>

> While the pattern each produces is similar there seems to be one major
> difference between the programs.
> 
> In my code as the recursion level gets larger the size of the overall
> square bounding the curve remains the same. The individual segments of
> the pattern get smaller.
...
> As I understand it a true Sierpinski curve will fit into the unit square
> at any level of recursion. So while the code you supplied creates the
> right pattern, because it grows in size it's not a Sierpinski curve.

You are right, to get the curve  filling a unit square when :level grows to
inf. one should manipulate with :b parameter - reduce it twice with each
increment of :level.

> I feel however that my code isn't optimal. It is a literal translation
> of the algorithm to draw the curve. 

I don't know, what algorithm do You consider. There are 4 recursive
procedures in Your program. This solution is very similar to that used by
Niklaus Wirth in his book "Algorithms + Data Structures = Programs"
(wonderful book indeed, and written by Pascal programming language
creator). But N.Wirth didn't use turtle graphic. In fact he use no really
graphic commands at all. There were only virtual "plot" and "setpen"
commands - something like setpos in Logo. 
I know Sierpinski's curve from "Mathematical snapshots" of Hugo Steinhaus.
The original Polish edition of this book from 1938 does not consider any
computer drawing algorithm of course. The base figure is divided to 2
fragments, which may be described as follows:

to angle :b
 fd :b lt 45 fd :b rt 90 fd :b rt 90 fd :b lt 45 fd :b
end

to bottom :b
 fd :b lt 45 fd :b lt 45 fd :b
end

;The whole curve is given by

to S.curve :level :b
 repeat 4 [hiper.angle :level :b]
end

;Now we should define hiper.angle and hiper.bottom

to hiper.angle :level :b
 if :level=0 [angle :b stop]
 hiper.bottom :level-1 :b/2
 repeat 3 [hiper.angle :level-1 :b/2]
 hiper.bottom :level-1 :b/2
end

to hiper.bottom :level :b
 if :level=0 [bottom :b stop]
 hiper.bottom :level-1 :b/2
 hiper.angle :level-1 :b/2
 hiper.bottom :level-1 :b/2
end

You may see, that S.curve fits in unit square.

This could be an original Sierpinski's algorithm if there were computers
and Logo in Lwow (Poland) in 1930-ies.

BTW1 - this is neither Sierpinski nor Steinhaus in Microsoft Encarta. Mr
Gates - I don't love you any more.

BTW2 -  It is an interesting variation of Sierpinski's curve introduced by
Wirth in his book. I attach this figure without Logo code. Have a fun an
discover it :-) 

Best regards
Andrzej B.

w1.gif (Obraz GIF)



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home