generated from mwc/problemset_typeface
224 lines
3.5 KiB
Python
224 lines
3.5 KiB
Python
# typeface.py
|
|
# By Chris Proctor and Patrick Wick
|
|
|
|
# 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 segment(grids,unit):
|
|
pendown()
|
|
forward(grids*unit)
|
|
penup()
|
|
|
|
def diagonal(grids,unit):
|
|
pendown()
|
|
forward(grids*unit*sqrt(2))
|
|
penup()
|
|
|
|
def no_pen(grids,unit):
|
|
penup()
|
|
forward(grids*unit)
|
|
pendown()
|
|
|
|
def draw_letter_a(unit):
|
|
pass
|
|
|
|
def draw_letter_b(unit):
|
|
pass
|
|
|
|
def draw_letter_c(unit):
|
|
no_pen(3,unit)
|
|
|
|
segment(4,unit)
|
|
left(90)
|
|
segment(2,unit)
|
|
left(90)
|
|
segment(2,unit)
|
|
right(45)
|
|
diagonal(2,unit)
|
|
right(90)
|
|
diagonal(2,unit)
|
|
right(45)
|
|
segment(2,unit)
|
|
left(90)
|
|
segment(2,unit)
|
|
left(90)
|
|
segment(4,unit)
|
|
left(45)
|
|
diagonal(2,unit)
|
|
left(45)
|
|
segment(4,unit)
|
|
left(45)
|
|
diagonal(2,unit)
|
|
|
|
right(135)
|
|
no_pen(3,unit)
|
|
left(180)
|
|
|
|
def draw_letter_d(unit):
|
|
no_pen(1,unit)
|
|
|
|
# the outline of the D
|
|
segment(5,unit)
|
|
left(45)
|
|
diagonal(1,unit)
|
|
left(45)
|
|
segment(6,unit)
|
|
left(45)
|
|
diagonal(1,unit)
|
|
left(45)
|
|
segment(5,unit)
|
|
left(90)
|
|
segment(8,unit)
|
|
|
|
left(90)
|
|
no_pen(2,unit)
|
|
left(90)
|
|
no_pen(2,unit)
|
|
|
|
# the inner part of the D
|
|
segment(4,unit)
|
|
right(90)
|
|
segment(1,unit)
|
|
right(45)
|
|
diagonal(1,unit)
|
|
right(45)
|
|
segment(2,unit)
|
|
right(45)
|
|
diagonal(1,unit)
|
|
right(45)
|
|
segment(1,unit)
|
|
|
|
no_pen(3,unit)
|
|
left(90)
|
|
no_pen(2,unit)
|
|
left(90)
|
|
|
|
def draw_letter_e(unit):
|
|
pass
|
|
|
|
def draw_letter_f(unit):
|
|
pass
|
|
|
|
def draw_letter_g(unit):
|
|
pass
|
|
|
|
def draw_letter_h(unit):
|
|
pass
|
|
|
|
def draw_letter_i(unit):
|
|
pass
|
|
|
|
def draw_letter_j(unit):
|
|
pass
|
|
|
|
def draw_letter_k(unit):
|
|
no_pen(1,unit)
|
|
left(90)
|
|
segment(8,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
left(135)
|
|
diagonal(2,unit)
|
|
right(45)
|
|
segment(2,unit)
|
|
right(90)
|
|
segment(1,unit)
|
|
right(45)
|
|
diagonal(3,unit)
|
|
left(90)
|
|
diagonal(3,unit)
|
|
right(45)
|
|
segment(1,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
right(45)
|
|
diagonal(2,unit)
|
|
left(135)
|
|
segment(2,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
|
|
no_pen(1,unit)
|
|
right(180)
|
|
|
|
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):
|
|
no_pen(2,unit)
|
|
|
|
left(135)
|
|
diagonal(1,unit)
|
|
right(45)
|
|
segment(7,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
right(90)
|
|
segment(5,unit)
|
|
left(45)
|
|
diagonal(1,unit)
|
|
left(90)
|
|
diagonal(1,unit)
|
|
left(45)
|
|
segment(5,unit)
|
|
right(90)
|
|
segment(2,unit)
|
|
right(90)
|
|
segment(7,unit)
|
|
right(45)
|
|
diagonal(1,unit)
|
|
right(45)
|
|
segment(4,unit)
|
|
|
|
no_pen(2,unit)
|
|
right(180)
|
|
|
|
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
|