problemset_typeface/typeface.py

233 lines
3.8 KiB
Python

# typeface.py
# By Chris Proctor and _________
# Contains one function for each letter in the English alphabet.
# Each function should draw its letter at a scale of `unit`, and then
# return back to the same position and heading where it started.
# Note: The `sqrt` function from math may be helpful--if you want to
# move the turtle along the diagonal of a square with side length x,
# the turtle should move a distance of sqrt(x)
from turtle import *
from math import sqrt
def fly(unit):
penup()
fd(unit)
pendown()
def flyto(x, y):
penup()
goto(x, y)
pendown()
def triangle(unit):
"Draws a 2x1 isocolese triangle"
lt(45)
fd(unit * sqrt(2))
rt(90)
fd(unit * sqrt(2))
rt(135)
fd(2 * unit)
rt(180)
def curve(vertical_units, diagonal_units, horizontal_units, right_turn=True):
"Draws a curve to the right: up, diag, horizontal, diag, down."
turn = right if right_turn else left
fd(vertical_units)
turn(45)
fd(diagonal_units * sqrt(2))
turn(45)
fd(horizontal_units)
turn(45)
fd(diagonal_units * sqrt(2))
turn(45)
fd(vertical_units)
def draw_letter_a(unit):
fly(unit)
lt(90)
fd(unit*3)
curve(unit*3, unit*2, unit*2)
curve(unit*3, 0, unit*2)
lt(90)
fd(unit*2)
lt(90)
curve(unit*3, 0, unit*2)
fd(unit)
rt(90)
fly(2*unit)
lt(90)
curve(unit, unit, 0)
rt(90)
fd(2*unit)
fly(unit*3)
lt(90)
fly(4*unit)
lt(90)
def draw_letter_b(unit):
fly(unit)
lt(90)
fd(8*unit)
rt(90)
fd(2*unit)
# bubbles
rt(90)
fly(unit)
lt(90)
curve(unit, unit, 0)
rt(90)
fd(2*unit)
rt(180)
fly(4*unit)
lt(90)
curve(unit, unit, 0)
rt(90)
fd(2*unit)
fly(5*unit)
rt(90)
# right side
fd(2*unit)
curve(0, 2*unit, 0)
rt(180)
curve(0, 2*unit, 0)
fd(4*unit)
fly(unit)
rt(180)
def draw_letter_c(unit):
fly(7*unit)
rt(180)
curve(4*unit, 2*unit, 4*unit)
rt(90)
fd(2*unit)
fly(4*unit)
rt(90)
curve(3*unit, unit, 2*unit)
rt(90)
fly(4*unit)
fd(2*unit)
rt(90)
fly(7*unit)
rt(180)
def draw_letter_d(unit):
fly(unit)
lt(90)
fd(8*unit)
rt(90)
curve(4*unit, 2*unit, 4*unit)
bk(2*unit)
rt(90)
fly(2*unit)
fd(4*unit)
rt(90)
curve(unit, unit, 2*unit)
fly(3*unit)
lt(90)
fly(2*unit)
lt(90)
def draw_letter_e(unit):
fly(3*unit)
rt(180)
curve(2*unit, 0, 8*unit)
curve(4*unit, 0, 2*unit)
curve(0, 0, -unit)
curve(4*unit, 0, 2*unit)
curve(0, 0, -unit)
curve(4*unit, 0, 2*unit)
fly(3*unit)
rt(180)
def draw_letter_f(unit):
fly(3*unit)
rt(180)
curve(2*unit, 0, 8*unit)
curve(4*unit, 0, 2*unit)
curve(0, 0, -unit)
curve(4*unit, 0, 2*unit)
lt(90)
fd(3*unit)
rt(90)
fly(3*unit)
rt(180)
def draw_letter_g(unit):
fly(7*unit)
rt(180)
curve(4*unit, 2*unit, 4*unit)
rt(90)
fd(2*unit)
rt(90)
fd(2*unit)
curve(unit, unit, 2*unit, False)
lt(90)
curve(2*unit, 0, 2*unit)
fd(2*unit)
rt(90)
fly(7*unit)
rt(180)
def draw_letter_h(unit):
pass
def draw_letter_i(unit):
pass
def draw_letter_j(unit):
pass
def draw_letter_k(unit):
pass
def draw_letter_l(unit):
pass
def draw_letter_m(unit):
pass
def draw_letter_n(unit):
pass
def draw_letter_o(unit):
pass
def draw_letter_p(unit):
pass
def draw_letter_q(unit):
pass
def draw_letter_r(unit):
pass
def draw_letter_s(unit):
pass
def draw_letter_t(unit):
pass
def draw_letter_u(unit):
pass
def draw_letter_v(unit):
pass
def draw_letter_w(unit):
pass
def draw_letter_x(unit):
pass
def draw_letter_y(unit):
pass
def draw_letter_z(unit):
pass