Skip to content

Instantly share code, notes, and snippets.

@ryanbugden
Created April 12, 2023 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanbugden/c28e2fe2edcf2b812fc2cca27f6e050c to your computer and use it in GitHub Desktop.
Save ryanbugden/c28e2fe2edcf2b812fc2cca27f6e050c to your computer and use it in GitHub Desktop.
When you finish your typeface, run this and look to the font overview for a congratulatory message.
# menuTitle: I Finished the Typeface.
from mojo.UI import CurrentFontWindow
import math
import time
f = CurrentFont()
fo = CurrentFontWindow().fontOverview
v = fo.getGlyphCollection().getGlyphCellView()
cw = v.getCellSize()[0]
vw = v.frameSize().width
vh = v.frameSize().height
color_choice = (0,0,1,1)
pattern = '''.. . ..... .. . .. .. .... ...... ...... ...... ..... .. . ......
.. . .. .. .. . ... ... . .. .. .. .. .. .. .. ... . ..
.... .. .. .. . . ... .. ...... .. .. ..... ..... .. .. . .. . ..
.. .. .. .. . . . .. . .. .. .. .. .. .. .. . ... ..
.. .. .. .. . . .. . .. .. .. .. .. .. .. . .. ..
.. ..... .... . .. . .. ...... ...... .. ..... . . ..
'''
cells_per_row = math.floor(vw/cw)
rows_with_gnames = {}
i = 0
row_num = 0
g_list = []
for g_name in f.glyphOrder:
g_list.append(g_name)
i += 1
if i >= cells_per_row:
rows_with_gnames.update({row_num: g_list})
i = 0
g_list = []
row_num += 1
# save the colors you already have
names_and_colors = {}
for g_name in f.glyphOrder:
names_and_colors.update({g_name: f[g_name].markColor})
for g in f:
g.markColor = None
frames = int(len(pattern.split("\n")[1])) + cells_per_row
# paint the words
for frame_i in range(frames):
for row_num, g_names in rows_with_gnames.items():
# only do the first few rows
if row_num > len(pattern.split("\n")) - 1:
break
line = " "*cells_per_row + pattern.split("\n")[row_num] + " "*100
line = line[frame_i:]
letter_i = 0
for letter in line:
g = f[g_names[letter_i]]
g.markColor = None
if letter == ".":
g.markColor = color_choice
letter_i += 1
# can only do some of the message at a time
if letter_i > len(g_names) - 1:
break
# for some reason, printing something is necessary if you want to see each frame?
print("YOU DID IT.")
# restore the mark colors you had before
for g_name, color in names_and_colors.items():
f[g_name].markColor = color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment