generated from mwc/problemset_typeface
234 lines
3.9 KiB
Python
234 lines
3.9 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 draw_letter_a(size):
|
|
pass
|
|
|
|
|
|
def draw_letter_b(unit):
|
|
pass
|
|
|
|
def draw_letter_c(unit):
|
|
pass
|
|
|
|
def draw_letter_d(unit):
|
|
pass
|
|
|
|
def draw_letter_e(unit):
|
|
pass
|
|
|
|
def draw_letter_f(unit):
|
|
pass
|
|
|
|
def draw_letter_g(unit):
|
|
pass
|
|
|
|
def draw_letter_h(unit):
|
|
penup()
|
|
forward(unit * 1)
|
|
pendown()
|
|
left(90)
|
|
forward(unit * 6)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 2)
|
|
left(90)
|
|
forward(unit * 1)
|
|
left(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 6)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 3)
|
|
left(90)
|
|
forward(unit * 1)
|
|
left(90)
|
|
forward(unit * 3)
|
|
right(90)
|
|
forward(unit * 2)
|
|
"Above is body of the H"
|
|
penup()
|
|
right(90)
|
|
forward(unit * 1)
|
|
right(90)
|
|
forward(unit * .5)
|
|
pendown()
|
|
def rectangle(width,height):
|
|
for _ in range(2):
|
|
forward(width)
|
|
left(90)
|
|
forward(height)
|
|
left(90)
|
|
rectangle(unit * .5,unit * 4)
|
|
penup()
|
|
forward(unit * 3.5)
|
|
pendown()
|
|
rectangle(unit * .5, unit * 4)
|
|
penup()
|
|
left(90)
|
|
forward(unit * 2.75)
|
|
pendown()
|
|
left(90)
|
|
rectangle(unit * 3, unit * .5)
|
|
penup()
|
|
forward(unit * 5)
|
|
left(90)
|
|
forward(unit * 3.75)
|
|
left(90)
|
|
|
|
|
|
|
|
def draw_letter_i(unit):
|
|
penup()
|
|
forward(unit * 3)
|
|
left(90)
|
|
forward(unit * 6)
|
|
def square(side_length):
|
|
for _ in range(4):
|
|
forward(side_length)
|
|
right(90)
|
|
pendown()
|
|
square(unit * 1)
|
|
right (180)
|
|
penup()
|
|
forward(unit * 1)
|
|
pendown()
|
|
forward(unit * 5)
|
|
left(90)
|
|
forward(unit * 1)
|
|
left(90)
|
|
forward(unit * 5)
|
|
left(90)
|
|
forward(unit * 1)
|
|
penup()
|
|
left(90)
|
|
forward(unit * 5)
|
|
right(90)
|
|
forward(unit * 3)
|
|
right(180)
|
|
|
|
def draw_letter_j(unit):
|
|
pass
|
|
|
|
def draw_letter_k(unit):
|
|
pass
|
|
|
|
def draw_letter_l(unit):
|
|
penup()
|
|
forward(unit * 2)
|
|
pendown()
|
|
left(90)
|
|
forward(unit * 7)
|
|
"Above draws initial line in L"
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 5)
|
|
left(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(90)
|
|
forward(unit * 4)
|
|
penup()
|
|
forward(unit * 2)
|
|
right(180)
|
|
|
|
|
|
def draw_letter_m(unit):
|
|
pass
|
|
|
|
def draw_letter_n(unit):
|
|
pass
|
|
|
|
def draw_letter_o(unit):
|
|
pass
|
|
|
|
def draw_letter_p(unit):
|
|
penup()
|
|
forward(unit * 1)
|
|
pendown()
|
|
left(90)
|
|
forward(unit * 6)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(45)
|
|
forward(unit * sqrt(2))
|
|
right(45)
|
|
forward(unit * 1)
|
|
right(45)
|
|
forward(unit * sqrt(2))
|
|
right(45)
|
|
forward(unit * .5)
|
|
left(90)
|
|
forward(unit * 3)
|
|
right(90)
|
|
forward(unit * 1.5)
|
|
penup()
|
|
right(90)
|
|
forward(unit * 4.75)
|
|
right(90)
|
|
forward(unit * 1)
|
|
pendown()
|
|
def square(side_length):
|
|
for _ in range(4):
|
|
forward(side_length)
|
|
right(90)
|
|
square(unit * .75)
|
|
right(90)
|
|
penup()
|
|
forward(unit * 4.75)
|
|
right(90)
|
|
forward(unit * 2)
|
|
right(180)
|
|
|
|
|
|
|
|
|
|
|
|
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
|