📚 The CoCalc Library - books, templates and other resources
License: OTHER
"""This module contains a code example related to12Think Python, 2nd Edition3by Allen Downey4http://thinkpython2.com56Copyright 2015 Allen Downey78License: http://creativecommons.org/licenses/by/4.0/9"""1011from __future__ import print_function, division1213import turtle1415from polygon import arc161718def petal(t, r, angle):19"""Draws a petal using two arcs.2021t: Turtle22r: radius of the arcs23angle: angle (degrees) that subtends the arcs24"""25for i in range(2):26arc(t, r, angle)27t.lt(180-angle)282930def flower(t, n, r, angle):31"""Draws a flower with n petals.3233t: Turtle34n: number of petals35r: radius of the arcs36angle: angle (degrees) that subtends the arcs37"""38for i in range(n):39petal(t, r, angle)40t.lt(360.0/n)414243def move(t, length):44"""Move Turtle (t) forward (length) units without leaving a trail.45Leaves the pen down.46"""47t.pu()48t.fd(length)49t.pd()505152bob = turtle.Turtle()5354# draw a sequence of three flowers, as shown in the book.55move(bob, -100)56flower(bob, 7, 60.0, 60.0)5758move(bob, 100)59flower(bob, 10, 40.0, 80.0)6061move(bob, 100)62flower(bob, 20, 140.0, 20.0)6364bob.hideturtle()65turtle.mainloop()666768