4.6.3. Draw a polygonΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'''
Draw a `n` sided polygon
'''
from turtleplotbot import TurtlePlotBot
bot=TurtlePlotBot()

def polygon(bot, sides, length):
    '''
    Draw a 'sides' sided polygon

    Args:
        sides: number of sides in polygon
        length: length of eacg side
    '''
    angle = 360 / sides
    bot.pendown()
    for _ in range(sides):
        bot.forward(length)
        bot.right(angle)

    bot.penup()

polygon(bot, 8, 20)
bot.done()

__import__("menu")      # return to turtleplotbot menu

polygon.py