Created
June 8, 2020 19:25
-
-
Save ryanbugden/b9719eaff702f31480c6dd8b95177e63 to your computer and use it in GitHub Desktop.
Scramble up the glyphs you've selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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