generated from mwc/problemset_typeface
324 lines
6.0 KiB
Python
324 lines
6.0 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
|
|
from math import atan
|
|
from math import degrees
|
|
|
|
def draw_letter_a(unit):
|
|
penup()
|
|
forward(unit)
|
|
pendown()
|
|
forward(1.5 * unit)
|
|
left(degrees(atan(2)))
|
|
forward(sqrt(5) * 1.5 * unit)
|
|
right(degrees(atan(2)))
|
|
forward(unit)
|
|
right(90)
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(2 * unit)
|
|
left(90)
|
|
forward(8 * unit)
|
|
left(90)
|
|
forward(2 * unit)
|
|
left(degrees(atan(2)))
|
|
forward(sqrt(5) * 4 * unit)
|
|
left(180 - degrees(atan(2)))
|
|
penup()
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(4 * unit)
|
|
pendown()
|
|
right(90)
|
|
forward(1 * unit)
|
|
left(90)
|
|
forward(2 * unit)
|
|
left(90 + degrees(atan(2)))
|
|
forward(sqrt(5) * unit)
|
|
penup()
|
|
forward(sqrt(5) * 2 * unit)
|
|
right(degrees(atan(2)))
|
|
forward(2 * unit)
|
|
right(180)
|
|
pendown()
|
|
|
|
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):
|
|
#print(heading())
|
|
#print(pos())
|
|
circle(unit,90)
|
|
forward(6 * unit)
|
|
circle(unit,90)
|
|
right(180)
|
|
forward(7 * unit)
|
|
right(90)
|
|
forward(2 * unit)
|
|
circle(-unit,-90)
|
|
left(180)
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(2 * unit)
|
|
left(90)
|
|
forward(4 * unit)
|
|
right(90)
|
|
forward(2 * unit)
|
|
circle(-unit,-90)
|
|
left(180)
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(3 * unit)
|
|
circle(unit,90)
|
|
left(180)
|
|
forward(4 * unit)
|
|
right(180)
|
|
|
|
|
|
def draw_letter_g(unit):
|
|
pass
|
|
|
|
def draw_letter_h(unit):
|
|
for i in range(2):
|
|
circle(unit,90)
|
|
forward(6 * unit)
|
|
circle(unit,90)
|
|
right(180)
|
|
forward(3.5 * unit)
|
|
circle(-unit,-90)
|
|
right(180)
|
|
forward(1.5 * unit)
|
|
circle(unit,90)
|
|
forward(1 * unit)
|
|
circle(unit,90)
|
|
forward(1.5 * unit)
|
|
circle(unit,90)
|
|
right(180)
|
|
forward(3.5 * unit)
|
|
right(180)
|
|
|
|
|
|
def draw_letter_i(unit):
|
|
pass
|
|
|
|
def draw_letter_j(unit):
|
|
# print(heading())
|
|
# print(pos())
|
|
left(90)
|
|
penup()
|
|
forward(8 * unit)
|
|
right(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(6 * unit)
|
|
right(90)
|
|
forward(6 * unit)
|
|
circle(-2 * unit, 90)
|
|
forward(2 * unit)
|
|
circle(-2 * unit, 90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(2 * unit)
|
|
right(90)
|
|
forward(unit)
|
|
circle(unit, 180)
|
|
forward(4 * unit)
|
|
left(90)
|
|
forward(4 * unit)
|
|
right(90)
|
|
forward(2 * unit)
|
|
penup()
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(8 * unit)
|
|
left(90)
|
|
|
|
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):
|
|
circle(unit,90)
|
|
forward(6 * unit)
|
|
circle(unit,90)
|
|
right(180)
|
|
forward(5 * unit)
|
|
circle(-2*unit,180)
|
|
forward(2 * unit)
|
|
left(90)
|
|
forward(3 * unit)
|
|
circle(unit,90)
|
|
left(180)
|
|
forward(4 * unit)
|
|
right(180)
|
|
penup()
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(7 * unit)
|
|
right(90)
|
|
pendown()
|
|
forward(unit)
|
|
circle(-unit,180)
|
|
forward(unit)
|
|
right(90)
|
|
forward(2 * unit)
|
|
penup()
|
|
left(90)
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(7 * unit)
|
|
left(90)
|
|
|
|
|
|
|
|
|
|
def draw_letter_q(unit):
|
|
penup()
|
|
forward(3 * unit)
|
|
pendown()
|
|
forward(2 * unit)
|
|
left(45)
|
|
forward(sqrt(2) * unit / 2)
|
|
penup()
|
|
forward(sqrt(2) * unit / 2)
|
|
pendown()
|
|
forward(2 * sqrt(2) * unit)
|
|
left(45)
|
|
for i in range(3):
|
|
forward(2 * unit)
|
|
left(45)
|
|
forward(3 * sqrt(2) * unit)
|
|
left(45)
|
|
penup()
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit)
|
|
right(45)
|
|
for i in range(2):
|
|
pendown()
|
|
forward(sqrt(2) * unit)
|
|
penup()
|
|
forward(sqrt(2) * unit)
|
|
pendown()
|
|
forward(sqrt(2) * unit)
|
|
left(90)
|
|
for i in range(2):
|
|
forward(3 * sqrt(2) * unit)
|
|
left(90)
|
|
forward(sqrt(2) * unit)
|
|
left(45)
|
|
forward(4 * unit)
|
|
right(135)
|
|
penup()
|
|
forward(sqrt(2) * unit)
|
|
right(45)
|
|
pendown()
|
|
forward(2 * unit)
|
|
penup()
|
|
forward(2 * unit)
|
|
pendown()
|
|
left(45)
|
|
forward(sqrt(2) * unit)
|
|
right(135)
|
|
forward(unit)
|
|
right(45)
|
|
forward(sqrt(2) * unit / 2)
|
|
penup()
|
|
left(90)
|
|
forward(sqrt(2) * unit / 2)
|
|
right(45)
|
|
forward(5 * unit)
|
|
right(180)
|
|
|
|
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):
|
|
penup()
|
|
forward(3 * unit)
|
|
left(90)
|
|
forward(4 * unit)
|
|
right(degrees(atan(2 / 3)))
|
|
pendown()
|
|
for i in range(2):
|
|
forward(sqrt(13) * unit)
|
|
left(90 + degrees(atan(2 / 3)))
|
|
forward(4 * unit)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(6 * unit)
|
|
right(90)
|
|
forward(unit)
|
|
right(degrees(atan(2 / 3)))
|
|
forward(sqrt(13) * unit)
|
|
penup()
|
|
right(90 - degrees(atan(2 / 3)))
|
|
forward(unit / 2.0)
|
|
left(90 - degrees(atan(2/3)))
|
|
pendown()
|
|
for i in range(2):
|
|
forward(sqrt(13) * unit)
|
|
right(90 - degrees(atan(2 / 3)))
|
|
forward(unit)
|
|
right(90 + degrees(atan(2 / 3)))
|
|
forward(sqrt(13) * unit)
|
|
left(90 + degrees(atan(2 / 3)))
|
|
penup()
|
|
forward(3.5 * unit)
|
|
left(90)
|
|
forward(4 * unit)
|
|
left(90)
|