Hi!
And there is update of code in the Kturtle v0.8:
# First, define subfunctions to draw the squares
# and the triangle. Make all the drawing functions end up
# in their starting position and direction. That return-to-start
# is crucial for the recursive drawing to work
learn square $length {
repeat 4 {
forward $length
turnleft 90
}
}
learn triangle_from_hypotenuse $length {
turnright 36.87 # 90-acos(5/3) # Later versions of
forward 3*$length/5 # kturtle have trig funcs
turnright 90
forward 4*$length/5
turnleft 36.87
backward $length
turnleft 90
}
learn triangle_and_three_squares_recurse $length {
$stopping_length = 3
# First draw the big square
square $length
# Now move to starting point for triangle
forward $length
turnleft 90
forward $length
turnright 90
# Now draw the triangle
triangle_from_hypotenuse $length
# Now move to start of side3 square
turnright 36.87
forward 3*$length/5
turnleft 90
#########################
# Branch-off point 1. Either start a new set
# of drawings where the side3 square would be,
# or simply draw the side3 square
if $length > $stopping_length {
triangle_and_three_squares_recurse 3*$length/5
} else {
# Draw the side3 square
square 3*$length/5
}
# Now position for start of side4 square
backward 4*$length/5
turnright 90
#########################
# Branch-off point 2
if $length > $stopping_length {
triangle_and_three_squares_recurse 4*$length/5
} else {
square 4*$length/5
}
# Finally, return to starting position
turnleft 36.87
backward $length
}
reset
canvassize 800,700
go 400,650
triangle_and_three_squares_recurse 100
I was happy as a little child on the Christmas eve when the turtle
finally finished the job :-)
Enjoy!
Silvia
On 20 kol, 18:02, Raj <
rajeev.raiz...@gmail.com> wrote:
> Hi,
>
> Please feel free to include these on the project webpage
> if you think they would be useful.
> The code is quite highly commented.
>
>
http://www.nmr.mgh.harvard.edu/~raj/Logo/kturtle06_pythagoras_tree.logohttp://www.nmr.mgh.harvard.edu/~raj/Logo/kturtle06_pythagoras_tree_re...