📚 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 Point1 import Point, Rectangle16from Circle import Circle1718import polygon1920def draw_circle(t, circle):21"""Draws a circle.2223t: Turtle24circle: Circle25"""26t.pu()27t.goto(circle.center.x, circle.center.y)28t.fd(circle.radius)29t.lt(90)30t.pd()31polygon.circle(t, circle.radius)323334def draw_rect(t, rect):35"""Draws a rectangle.3637t: Turtle38rect: Rectangle39"""40t.pu()41t.goto(rect.corner.x, rect.corner.y)42t.setheading(0)43t.pd()4445for length in rect.width, rect.height, rect.width, rect.height:46t.fd(length)47t.rt(90)484950if __name__ == '__main__':51bob = turtle.Turtle()5253# draw the axes54length = 40055bob.fd(length)56bob.bk(length)57bob.lt(90)58bob.fd(length)59bob.bk(length)6061# draw a rectangle62box = Rectangle()63box.width = 100.064box.height = 200.065box.corner = Point()66box.corner.x = 50.067box.corner.y = 50.06869draw_rect(bob, box)7071# draw a circle72circle = Circle73circle.center = Point()74circle.center.x = 150.075circle.center.y = 100.076circle.radius = 75.07778draw_circle(bob, circle)7980# wait for the user to close the window81turtle.mainloop()828384