python - Recursive Function for drawing a tree in Turtle -


I am trying to attract a tree using a recursive function. This is my best shot I know I am away, but there is a problem in trying to fix it. Any help would be appreciated! Def svTree (trunkLength, level): "Turtle" uses the drawing function to return a tree with input of a certain level: two integer, trunk length and level " NewtrunkLength = trunkLength * .5 if level == 1: Penup () Other: Forward (trunk langement) left (45) svTree (trunk langang * 0.5, level -1) right (90) forward (trunkLength * .5) svTree ( TrunkLength * 0.5, Level-1) Left (45) Backward (trunk length) Right (trunkLength) Right (45) svTree (trunkLength * 0.5, Level-1) Left (90) svTree (trunkLength * 0.5, Level-1) Right (45) backward (trunkLength) svTree Return (newtrunkLength, Level-1)

Here's my new attempt: I think it's close because I can make Y but then I think my recursive step Faulty ... please help! Thanks! Def svTree (trunkLength, Level): Uses turtle drawing functions to return a tree with the input of "specified" levels: Two integer, trunk length and level "newtrunkLength" = TrunkLength * .5 if level = = 1: Penapp () Other: Forward (trunk langement) left (45) forward (trunkLength * 0.5) pen (backward) (trunkLength * 0.5) Right (90) Pandona () Forwarded (Trunk Langlane * .5) Penup () Backward (trunk langs .5) Right (180) left (45) right (180) svTree back (newtrunkLength, level-1) < p>

Copy-paste is a good sign that you are doing something wrong to find repeating parts.

Most More likely, you do not want to draw during backup, so call backward before penup () .

Its In addition, you want all the subtitles to be from the same point, so that you have to go back after each recurring call.

Finally, The returned value is not used, then return to do to get a recursive call in line?

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -