4.6.1. Draw a draw box

4.6.1.1. Simple Version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
The simple way to draw a box
'''

from turtleplotbot import TurtlePlotBot
bot=TurtlePlotBot()
bot.pendown()

bot.forward(30)
bot.left(90)

bot.forward(30)
bot.left(90)

bot.forward(30)
bot.left(90)

bot.forward(30)
bot.left(90)

bot.done()

__import__("menu")      # optional return to turtleplotbot menu

box_simple.py


4.6.1.2. Better way to draw a box

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
'''
Better way to draw a box
'''

from turtleplotbot import TurtlePlotBot
bot=TurtlePlotBot()
bot.pendown()

for _ in range(4):
    bot.forward(30)
    bot.left(90)

bot.done()

__import__("menu")      # optional return to turtleplotbot menu

box_better.py


4.6.1.3. Even better way to draw a box

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
Even better way to draw boxes
'''

from turtleplotbot import TurtlePlotBot
bot=TurtlePlotBot()

def box(bot, size):
    bot.pendown()

    for _ in range(4):
        bot.forward(size)
        bot.left(90)

    bot.penup()

box(bot, 10)
box(bot, 20)
box(bot, 30)

bot.done()

__import__("menu")      # optional return to turtleplotbot menu

box_even_better.py