Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
cc3c4f2846 | |
|
4dd16a7d26 |
157
typeface.py
157
typeface.py
|
@ -8,30 +8,171 @@
|
|||
# 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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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):
|
||||
pass
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue