Skip to content

Instantly share code, notes, and snippets.

@ryanbugden
Created June 8, 2020 19:25
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/b9719eaff702f31480c6dd8b95177e63 to your computer and use it in GitHub Desktop.
Save ryanbugden/b9719eaff702f31480c6dd8b95177e63 to your computer and use it in GitHub Desktop.
Scramble up the glyphs you've selected
# menuTitle : Scramble Selected Glyphs
from random import choice
f = CurrentFont()
# grab selection
gs = f.selectedGlyphNames
new_assign ={}
accounted = []
for g_name in gs:
g = f[g_name]
# make temp glyphs
temp_name = g_name + "_temp"
f.insertGlyph(g, name=temp_name)
# choose a target glyph to scramble to, at random
target_g = choice(gs)
while target_g in accounted:
target_g = choice(gs)
# capture unicode of the target glyph to reinstate later
uni = f[target_g].unicodes
# organize what's going where, and unicodes to keep
new_assign.update({target_g : [temp_name, uni]})
accounted.append(target_g)
# slip the temp glyphs into their final slot, assign unicodes, and delete temps
for target_g, [temp_name, uni] in new_assign.items():
f.insertGlyph(f[temp_name], name=target_g)
f[target_g].unicodes = uni
f.removeGlyph(temp_name)
f.changed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment