python - Drawing a snowflake using recursion -


i want create output this: 

enter image description here

i have use recursion.

so far , code looks like:

from turtle import *       def drawflake(length,depth):          fd(length)         input("first line done")         if depth>0:               left(60)             drawflake(length/3,depth-1)              input("1")             left(120)             drawflake(length/3,depth-1)             input("2")              left(120)             drawflake(length/3,depth-1)             input("3")              left(120)             drawflake(length/3,depth-1)             input("4")              left(120)             left(180)             #drawflake(length/3,depth-1)             input("1")              left(120)             drawflake(length/3,depth-1)              input("this last")             left(60)            left(180)         fd(length)   drawflake(100,3) 

and produces output this(here, n =3)

the issue long line @ left. there should no long line. instead, there should flake pattern

what doing wrong ?

enter image description here

edit::

this better managed come with. still not perfect :

def dofigure(length,depth):          left(120)         fd(length)         if depth>1:          dofigure(length/3,depth-1)          bk(length)         right(60)          fd(length)         if depth>1:          dofigure(length/3,depth-1)         bk(length)         right(60)          fd(length)         if depth>1:          dofigure(length/3,depth-1)         bk(length)         right(60)          fd(length)         if depth>1:          dofigure(length/3,depth-1)         bk(length)         right(60)          fd(length)         if depth>1:          dofigure(length/3,depth-1)         bk(length)         right(60)          fd(length)         if depth == 3:              dofigure(length/3,depth-1)         bk(length)         right(180) 

enter image description here

note 5th last line. having hard code value 3 correct value.

here solution: not perfect has bunch along main stems compared drawing posted.

let me know if works you.

from turtle import *

def drawflake(length, depth):     "draws flake"     if depth > 0:         _ in range(6):             forward(length)             drawflake(length // 3, depth - 1)             backward(length)             left(60)  drawflake(200,4) 

flake depth 4


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -