Typeface
A typeface (or font) is a styled way of representing text. Today we take for granted the ability to use lots of fonts everywhere, but making this possible took a huge amount of work. One of the major breakthroughs was Apple's introduction of TrueType, a system for drawing sharp outlines of each letter form instead of saving each letter as an image. Image-based fonts get pixellated when they are made too big, and become hard to read when they are made too small.
In this problem set, you will design a few letters for a typeface of your own design.
As with TrueType, each of your letters will be drawn in a way that scales to any size.
There is a function in typeface.py
(the only file you should edit) for each letter
of the English alphabet.
Each letter's function (draw_letter_a
, draw_letter_b
, etc.) should
have the turtle draw that letter.
- Assume the turtle starts at the bottom left corner of a square where the letter will be drawn. The turtle initially points to the right, along the bottom edge of the square.
- The turtle must end up in the same location, pointing the same direction, when it finishes drawing.
- Each letter's function takes one argument:
size
. The letter should be drawn on an 8-by-8 grid, where each square in the grid has side lengthsize
. That way, the same functions can be used to write text of any size.
Getting started
Get some scratch paper. Draw an 8-by-8 grid, nice and large. Choose a letter from
the English alphabet and draw it on the grid. It will be easier if you only use
horizontal, vertical, and diagonal lines, but you're welcome to use curves
(see the documentation for turtle.circle
) if you want a challenge.
Once you have drawn your letter, trace its lines with your finger. Which will be drawn first? When does the turtle need to turn or pick up the pen? Consider writing down a list of what the turtle needs to do. Then see if you can turn this into code.
Before you start programming, remember to get set up:
- ๐ป
mwc update
- ๐ป
cd Desktop/making_with_code/mwc1/unit1/problemset_typeface
- ๐ป
poetry shell
Once you have started writing code for the letter, save your work and test your program.
test.py
is provided for just this purpose. To test draw_letter_q
, run:
$ python test.py q
test.py
is perfect for testing individual letters. The other provided program,
proof.py
, draws a proof sheet with all the letters, at two different scales. After
you have a letter working with test.py
, try running:
$ python proof.py
Tips
- Each function's code block currently has a single statement,
pass
, which means "do nothing." Replace this with your own code. - Add a small amount of code, then test by running
python test.py x
(if you're working ondraw_letter_x
.) Repeat. - Test each letter using
test.py
until it is working perfectly. Then useproof.py
to see all your letters together. - You probably don't need any turtle functions other than
forward
,left
,right
,penup
, andpendown
. - The turtle should never move a fixed distance; it should always move a multiple
of
size
. If you want the turtle to move forward two grid squares, useforward(size * 2)
. - The length of a square's diagonal is its side length times the square root of 2.
We have already imported
sqrt
(the sqare root function) on line 13. If you want the turtle to move along one square's diagonal, useforward(size * sqrt(2))
. - If you notice yourself re-using the same pattern, consider defining a helper function. For example, one common pattern is picking up the pen, moving forward, and then putting the pen back down. Wouldn't it be nice to have a function for this?
def fly(distance):
penup()
forward(distance)
pendown()
Debugging
- If
test.py
is working, butproof.py
gets all messed up, you are probably not returning the turtle to its starting location and heading at the end of one of the letters. - If (when) you get stuck, use some debugging strategies:
- Run
test.py
and observe the turtle's motion very carefully. When does the error start? - Try removing code (paste it somewhere else) until you only have part of the letter, but at least that part is correct.
- Work with other people! Brainstorm together on Discord; ask {{teacher}} for help.
- Above all, take a break! If you ever find yourself trying to solve the same problem over and over for a long time, just walk away for a while.
- Run