Project: draw a letter
Plan a path, drive it, leave a trail.
Do this lesson in the simulatorEverything in this module in one run: plan a path, drive it by distance, turn or strafe at the corners, and leave a trail on the mat that spells something.
Plan first
The robot leaves a trail behind it in the simulator. To draw a letter, you plan the strokes as a list of moves. An L is two strokes: a long one down, then a short one to the right.
Write the plan as comments before any code:
# L: start top left, facing down
# 1. down 60 cm
# 2. turn to face right (or strafe)
# 3. right 30 cm
Stroke one
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
print("bottom of the L at", position())
The robot starts facing down the mat in this task (its heading is 180), so forward draws the downstroke.
Stroke two, two ways
With a turn:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
# face right
turn_left(30, angle=90)
# drive forward at 60 for 30 cm, then stop
forward(60, distance=30)
print("done at", position(), "facing", round(heading()))
With a strafe, no turning:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# drive forward at 60 for 60 cm, then stop
forward(60, distance=60)
# facing down, so "left" is to the right of the mat
left(60, distance=30)
print("done at", position(), "facing", round(heading()))
Which trail looks more like an L? The strafe version keeps the corner sharp.
Task: draw an L
Start at the top left facing down. Drive the long stroke into the corner zone, then the short stroke into the goal.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# stroke one, stroke two
Your own letters
The free-play simulator has no zones. Plan a letter from your name (T, E, F, H and Z are easy; S and O need drive with rotation) and draw it there.
Challenges
- Draw your first initial. Take a screenshot of the trail.
- Draw two letters, lifting the "pen" between them: drive to the start of the second letter in one move.
- Write
stroke(cm)andcorner(deg)functions and draw an E with them.