Python Forum
Manipulating code to draw a tree
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulating code to draw a tree
#9
from turtle import Turtle, mainloop
def tree(plist, l, a, f):
    """ plist is list of pens
    l is length of branch
    a is half of the angle between 2 branches
    f is factor by which branch is shortened
    from level to level."""
    if l > 5: 
        lst = []
        for p in plist:
            p.forward(l)
            q = p.clone()
            p.left(a)
            q.right(a)
            lst.append(p)
            lst.append(q)
        tree(lst, l*f, a, f)

def main():
    p = Turtle()
    p.color("green")
    p.pensize(5)
    p.speed(100)
    p.left(90)
    p.penup()
    p.goto(0,-200)
    p.pendown()
t = tree([p], 200, 65, 0.6)
main()
Reply


Messages In This Thread
Manipulating code to draw a tree - by Py_thon - Oct-09-2019, 04:28 AM
RE: Manipulating code to draw a tree - by Py_thon - Oct-10-2019, 11:24 AM
RE: Manipulating code to draw a tree - by Py_thon - Oct-10-2019, 07:06 PM
RE: Manipulating code to draw a tree - by Py_thon - Oct-10-2019, 09:15 PM
RE: Manipulating code to draw a tree - by sumana - Nov-21-2019, 05:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Manipulating panda dataframes more python-like badtwistoffate 4 2,174 Jan-31-2023, 04:30 AM
Last Post: deanhystad
  Manipulating List frenchyinspace 2 2,824 Oct-08-2019, 07:57 AM
Last Post: perfringo
  Manipulating __init__ method schniefen 5 3,683 May-06-2019, 11:22 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020