Spirals
We will now draw our first recursive function with the turtle. The goal is
to draw different kind of spirals with the same function, which prototype is
the following:
[!java|c]void [/!]spiral([!java|c]int [/!]steps[!scala]:Int[/!], [!java|c]int [/!]angle[!scala]:Int[/!], [!java|c]int [/!]length[!scala]:Int[/!], [!java|c]int [/!]increment[!scala]:Int[/!])
To help you understanding how to write it, here is an example of how the
parameters change during one specific call:
spiral(5, 90, 0, 3);
forward(0);
left(90);
spiral(4,90,3,3);
forward(3);
left(90);
spiral(3,90,6,3);
forward(6);
left(90);
spiral(2,90,9,3);
forward(9);
left(90);
spiral(1,90,12,3);
forward(12);
left(90);
spiral(0,90,12,3);
Note that you only have to write the function, not the initial call.
Each world will provide a specific set of initial parameters (use the
combobox to switch to other worlds). For example, the "Square Pyramid"
world will call your function as follows:
spiral(100, 90, 0, 3);