The dragon curve is a classical example of recursive method.
The definition of this curve is the following:
the dragon curve of order 1 is a vector between to arbitrary points P and Q,
the dragon curve of order n is the dragon curve of order n-1 between P and
R, followed by the same curve of order n-1 between Q and R,
where PRQ is an isosceles triangle with angle R being a right angle, and R
being at the right of the PQ vector. Thus, if P and Q coordinates are (x, y)
and (z, t), the coordinate (u, v) of R are given by:
u = (x + z)/2 + (t - y)/2 v = (y + t)/2 - (z - x)/2
The prototype of the method drawing the curve is the following:
[!java]void [/!]dragon([!java]int [/!]order[!scala]:Int[/!], [!java]double [/!]x[!scala]:Double[/!], [!java]double [/!]y[!scala]:Double[/!], [!java]double [/!]z[!scala]:Double[/!], [!java]double [/!]t[!scala]:Double[/!])
You should use the method setPos(x,y)
to put your turtle at
coordinates (x,y) and the method moveTo(z,t)
to draw a line
between the turtle position and the point(z,t).
Have a look at each world's objective view to understand how to write the function.