generated from mwc/problemset_typeface
I was very frustrated witht he positioning of the proofs but once I got it, i felt relieved and accomplished.
760 lines
13 KiB
Python
760 lines
13 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 turtle import goto
|
|
from math import sqrt
|
|
def draw_square(unit):
|
|
for i in range(4):
|
|
forward(unit)
|
|
left(90)
|
|
def start(unit):
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*6)
|
|
right(90)
|
|
|
|
|
|
|
|
def draw_letter_a(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
for i in range(2):
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
penup()
|
|
right(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
pendown()
|
|
draw_square(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_b(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(135)
|
|
penup()
|
|
forward(unit*sqrt(2))
|
|
right(45)
|
|
pendown()
|
|
draw_square(unit*2)
|
|
penup()
|
|
left(90)
|
|
forward(unit*3)
|
|
pendown()
|
|
right(90)
|
|
draw_square(unit)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_c(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*4)
|
|
left(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_d(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*4)
|
|
penup()
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_e(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*3)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_f(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*3)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2.5)
|
|
right(90)
|
|
forward(unit)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_g(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*4)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
def draw_letter_h(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2.5)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2.5)
|
|
right(90)
|
|
forward(unit)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_i(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit)
|
|
start(unit)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_j(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*4)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*.5)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_k(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*2.5)
|
|
left(150)
|
|
forward(unit*2.9)
|
|
right(60)
|
|
forward(unit*1)
|
|
right(120)
|
|
forward(unit*3.5)
|
|
left(60)
|
|
forward(unit*3.5)
|
|
right(120)
|
|
forward(unit*1)
|
|
right(60)
|
|
forward(unit*2.9)
|
|
left(150)
|
|
forward(unit*2.5)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
|
|
def draw_letter_l(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_m(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit)
|
|
right(65)
|
|
forward(unit*2.4)
|
|
left(130)
|
|
forward(unit*2.4)
|
|
right(65)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*3)
|
|
left(135)
|
|
forward(unit*1.4)
|
|
right(90)
|
|
forward(unit*1.4)
|
|
left(135)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
|
|
def draw_letter_n(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit)
|
|
right(57)
|
|
forward(sqrt((unit*3)**2+(unit*2)**2))
|
|
left(147)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit)
|
|
right(57)
|
|
forward(sqrt((unit*3)**2+(unit*2)**2))
|
|
left(147)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
def draw_letter_o(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*4)
|
|
penup()
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
pendown()
|
|
draw_square(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_p(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*2)
|
|
penup()
|
|
right(108)
|
|
forward(sqrt((unit*3)**2+(unit*1)**2))
|
|
right(72)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_q(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*2)
|
|
pendown()
|
|
forward(unit*5)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*5)
|
|
right(90)
|
|
forward(unit)
|
|
left(135)
|
|
forward(unit*1.5)
|
|
right(135)
|
|
forward(unit)
|
|
right(45)
|
|
forward(unit*1.5)
|
|
left(45)
|
|
forward(unit*2)
|
|
penup()
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit)
|
|
pendown()
|
|
for i in range(2):
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
def draw_letter_r(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit)
|
|
left(116.5)
|
|
forward(unit*sqrt(5))
|
|
right(116.5)
|
|
forward(unit)
|
|
right(63.5)
|
|
forward(unit*sqrt(5))
|
|
left(153.5)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*2)
|
|
penup()
|
|
right(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit*2)
|
|
pendown()
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
def draw_letter_s(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*3.5)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*3.5)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_t(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*3)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*5)
|
|
left(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit)
|
|
left(90)
|
|
forward(unit*5)
|
|
right(90)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_u(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*5)
|
|
left(90)
|
|
forward(unit*1)
|
|
left(90)
|
|
forward(unit*5)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_v(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*3)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
left(10)
|
|
forward(unit*sqrt(37))
|
|
right(100)
|
|
forward(unit*1.5)
|
|
right(80)
|
|
forward(unit*3.2)
|
|
left(160)
|
|
forward(unit*3.2)
|
|
right(80)
|
|
forward(unit*1.5)
|
|
right(100)
|
|
forward(unit*sqrt(37))
|
|
right(80)
|
|
forward(unit*2)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_w(unit):
|
|
x_pos, y_pos= pos()
|
|
start(unit)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*4)
|
|
left(153)
|
|
forward(unit*sqrt(1.25))
|
|
right(126)
|
|
forward(unit*sqrt(1.25))
|
|
left(153)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(63)
|
|
forward(unit*sqrt(1.25))
|
|
left(126)
|
|
forward(unit*sqrt(1.25))
|
|
right(63)
|
|
forward(unit*1.5)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
def draw_letter_x(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*2)
|
|
right(56)
|
|
forward(unit*sqrt((1.5)**2+1))
|
|
left(112)
|
|
forward(unit*sqrt((1.5)**2+1))
|
|
right(56)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(63)
|
|
forward(unit*sqrt((0.5)**2+1))
|
|
left(126)
|
|
forward(unit*sqrt((0.5)**2+1))
|
|
right(63)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(56)
|
|
forward(unit*sqrt((1.5)**2+1))
|
|
left(112)
|
|
forward(unit*sqrt((1.5)**2+1))
|
|
right(56)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(63)
|
|
forward(unit*sqrt((0.5)**2+1))
|
|
left(126)
|
|
forward(unit*sqrt((0.5)**2+1))
|
|
right(63)
|
|
forward(unit*1.5)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
def draw_letter_y(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2.5)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*.5)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
left(90)
|
|
forward(unit*2.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*3)
|
|
right(90)
|
|
forward(unit*1.5)
|
|
right(90)
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit*.5)
|
|
left(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*6)
|
|
right(90)
|
|
forward(unit*3.5)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|
|
|
|
|
|
|
|
def draw_letter_z(unit):
|
|
x_pos, y_pos= pos()
|
|
penup()
|
|
forward(unit*2)
|
|
left(90)
|
|
forward(unit)
|
|
pendown()
|
|
forward(unit*2)
|
|
right(45)
|
|
forward(unit*sqrt(8))
|
|
left(135)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*4)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(45)
|
|
forward(unit*sqrt(8))
|
|
left(135)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*2)
|
|
right(90)
|
|
forward(unit*4)
|
|
teleport(x_pos, y_pos)
|
|
setheading(0)
|
|
|