diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ab18bdb Binary files /dev/null and b/.DS_Store differ diff --git a/typeface.py b/typeface.py index b966bef..e1f6d92 100644 --- a/typeface.py +++ b/typeface.py @@ -1,5 +1,5 @@ # typeface.py -# By Chris Proctor and _________ +# By Chris Proctor and Tristan Gaeta # Contains one function for each letter in the English alphabet. # Each function should draw its letter at a scale of `unit`, and then @@ -9,8 +9,42 @@ # 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 turtle import (pos, teleport, goto) + +class Point(tuple): + "Class for doing element-wise arithmetic on tuples" + def __add__(self, other): + return Point((x + y for x, y in zip(self, other))) + + def __sub__(self, other): + return Point((x - y for x, y in zip(self, other))) + + def __rmul__(self, other): + return Point((other * x for x in self)) + + def __truediv__(self, other): + return Point((x / other for x in self)) + +def bezier(t, *points: tuple[float, ...]) -> Point: + "Recursive definition of a Bezier curve" + assert(len(points) > 0) + if len(points) == 1: + return Point(points[0]) + return (1-t) * bezier(t, *points[0:-1]) + t * bezier(t, *points[1:]) + +def draw_bezier(unit, segments, *points: tuple[float, ...]): + "Draws bezier and returns turtle to initial position" + segments = int(unit * (segments / 40)) + origin = pos() + points = tuple(origin + unit * Point(x) for x in points) + + teleport(*points[0]) + for i in range(0, segments + 1): + bz = bezier(i / segments, *points) + goto(bz) + + teleport(*origin) + def draw_letter_a(unit): pass @@ -19,7 +53,11 @@ def draw_letter_b(unit): pass def draw_letter_c(unit): - pass + draw_bezier(unit, 160, + (7, 7), + (0.5, 11.88), + (0.5, -3.88), + (7, 1)) def draw_letter_d(unit): pass @@ -46,7 +84,11 @@ def draw_letter_k(unit): pass def draw_letter_l(unit): - pass + draw_bezier(unit, 100, + (1.46, 8), + (5.27, -6.66), + (-5.94, 4.27), + (7, 0)) def draw_letter_m(unit): pass @@ -73,10 +115,18 @@ def draw_letter_t(unit): pass def draw_letter_u(unit): - pass + draw_bezier(unit, 100, + (0.5, 8), + (0, -2.5), + (8, -2.5), + (7, 8)) def draw_letter_v(unit): - pass + draw_bezier(unit, 80, + (1, 8), + (4, -0.33), + (3.44, -4.33), + (7, 8)) def draw_letter_w(unit): pass