Odp: LOGO-L> Sierpinski Curves]
Author Message
Odp: LOGO-L> Sierpinski Curves]

<snip>

Quote:
> 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.

Quote:
> 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.

Sat, 17 Jun 2000 03:00:00 GMT
Odp: LOGO-L> Sierpinski Curves]

Quote:

> <snip>
> > 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).

I should have said 'an' algorithm of course.  The idea for the curve
came from the web site I cited in the code:
He does reference the book by Wirth so perhaps that is way they are
similar.

I have run your new code and it does keep the curve in the unit square.
I haven't had tine to really look into it but it does appear simpler
than my code. It's always good to see a problem solved in a different
way, it forces us see in new ways.

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

Not having loved Mr Gates since early MSDOG I'll add this to my reasons
for feeling as I do.
Quote:

> 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 :-)

Looks good,  I look forward to playing around with it, thanks.

In the meantime I have attached a revised version of my code for the
curve.  It allows the different line segments to be drawn in different
colors.  This helps a lot in following the recursion taking place in the
program.   I have also renamed the segment procedures to Side i.e. aSeg
is now aSide.  This fits better with the spirit of the algorithm.  If
you map the a,b,c and d Sides to the top, right, bottom and left sides
of the square respectively the program may make more sense.

regards
--
Frank Caggiano

http://www.atlantic.net/~caggiano

to sierp :len :level :color
;; :len sets the oveall size of the finished square.
;; :level controls the recusion
;; :color is either 0 or 1, if 0 no color is set for the lines.
;;
;; The length equation was obtained from:
;;

make "len :len * 1 / ((power 2 (:level + 1)) - 2 + ((power 2 :level) *
sqrt 2))

ifelse :color = 1 [make "lineDrawer "colorLine]~
[make "lineDrawer "bwLine]

seth 135

aSide :len :level
rt 90 fd :len rt 90
bSide :len :level
rt 90 fd :len rt 90
cSide :len :level
rt 90 fd :len rt 90
dSide :len :level
rt 90 fd :len
end

to bwLine :len :colorVector
;; ignore colorVector in black and white version
;;
localmake "inPC pencolor
setpencolor [0 0 0]
fd :len lt 45 fd :len fd :len lt 45 fd :len
setpencolor :inPc
end

to colorLine :len :colorVector
localmake "inPC pencolor
setpencolor :colorVector
fd :len lt 45 fd :len fd :len lt 45 fd :len
setpencolor :inPC
end

to aSide :len :level
if :level < 1 [(invoke :lineDrawer :len [255 0 0])  stop]

aSide :len  :level - 1
rt 90 fd :len  rt 90
bSide :len  :level - 1
lt 45 fd :len  fd :len lt 45
dSide :len  :level - 1
rt 90 fd :len rt 90
aSide :len  :level - 1

end

to bSide :len :level
if :level < 1 [(invoke :lineDrawer :len [0 0 255]) stop]

bSide :len  :level - 1
rt 90 fd :len rt 90
cSide :len  :level - 1
lt 45 fd :len fd :len lt 45
aSide :len  :level - 1
rt 90 fd :len rt 90
bSide :len  :level - 1

end

to cSide :len :level
if :level < 1 [(invoke :lineDrawer :len [0 255 0]) stop]

cSide :len  :level - 1
rt 90 fd :len rt 90
dSide :len  :level - 1
lt 45 fd :len fd :len lt 45
bSide :len  :level - 1
rt 90 fd :len rt 90
cSide :len   :level - 1
end

to dSide :len :level
if :level < 1 [(invoke :lineDrawer :len [0 255 255]) stop]

dSide :len  :level - 1
rt 90 fd :len rt 90
aSide :len  :level - 1
lt 45 fd :len fd :len lt 45
cSide :len  :level - 1
rt 90 fd :len rt 90
dSide :len  :level - 1
end
---------------------------------------------------------------

Sun, 18 Jun 2000 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages