generated from mwc/problemset_typeface
	
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# proof.py
 | 
						|
# By Chris Proctor
 | 
						|
#
 | 
						|
# Draws a proof sheet, showing each letter in `typeface`
 | 
						|
# at two different sizes. 
 | 
						|
 | 
						|
# ---------------------------------------------------------
 | 
						|
# ⚠️  You don't need to read or understand this code. 
 | 
						|
# Some of the code uses techniques you haven't learned yet. 
 | 
						|
# That said, feel free to poke around and don't hesistate to 
 | 
						|
# ask if you're curious.
 | 
						|
 | 
						|
from turtle import *
 | 
						|
from grid import draw_grid, GRID_ROWS
 | 
						|
from superturtle.movement import no_delay
 | 
						|
import typeface
 | 
						|
 | 
						|
GRID_COLOR = "lightgrey"
 | 
						|
GRID_SIZE = 1
 | 
						|
LETTER_COLOR = "black"
 | 
						|
LETTER_SIZE = 3
 | 
						|
LETTERS_PER_ROW = 7
 | 
						|
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
 | 
						|
 | 
						|
def fly(distance):
 | 
						|
    penup()
 | 
						|
    forward(distance)
 | 
						|
    pendown()
 | 
						|
 | 
						|
def flyto(x, y):
 | 
						|
    penup()
 | 
						|
    goto(x, y)
 | 
						|
    pendown()
 | 
						|
 | 
						|
def go_to_next_line(unit):
 | 
						|
    right(180)
 | 
						|
    fly((GRID_ROWS + 1) * LETTERS_PER_ROW * unit)
 | 
						|
    left(90)
 | 
						|
    fly((GRID_ROWS + 1) * unit)
 | 
						|
    left(90)
 | 
						|
 | 
						|
def draw_proof_sheet(unit):
 | 
						|
    rows = ((len(ALPHABET) - 1) // LETTERS_PER_ROW) + 1
 | 
						|
    left(90)
 | 
						|
    fly((GRID_ROWS + 1) * (rows - 1) * unit)
 | 
						|
    right(90)
 | 
						|
    for i, letter in enumerate(ALPHABET):
 | 
						|
        if i > 0 and i % LETTERS_PER_ROW == 0:
 | 
						|
            go_to_next_line(unit)
 | 
						|
        color(GRID_COLOR)
 | 
						|
        pensize(GRID_SIZE)
 | 
						|
        draw_grid(unit)
 | 
						|
        color(LETTER_COLOR)
 | 
						|
        pensize(LETTER_SIZE)
 | 
						|
        letter_function = getattr(typeface, f"draw_letter_{letter}")
 | 
						|
        letter_function(unit)
 | 
						|
        fly((GRID_ROWS + 1) * unit)
 | 
						|
    fly((GRID_ROWS + 1) * (len(ALPHABET) % LETTERS_PER_ROW) * -unit)
 | 
						|
 | 
						|
with no_delay():
 | 
						|
    flyto(-310, -60)
 | 
						|
    draw_proof_sheet(10)
 | 
						|
    flyto(-310, -260)
 | 
						|
    draw_proof_sheet(5)
 | 
						|
input()
 | 
						|
 |