Created
January 27, 2023 21:16
-
-
Save typemytype/9782256a570b3f52f32343cad72ede1e to your computer and use it in GitHub Desktop.
Glyph to css clippath polygon
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
""" | |
draw a shape | |
useage in clip-path: polygon(...); | |
""" | |
glyph = CurrentGlyph() | |
for contour in glyph: | |
bounds = contour.bounds | |
if bounds: | |
minx, miny, maxx, maxy = bounds | |
w = maxx - minx | |
h = maxy - miny | |
relativePoints = [] | |
for point in contour.points: | |
x = (point.x - minx) / w | |
y = (point.y - miny) / h | |
relativePoints.append(f"{x * 100}% {y * 100}%") | |
print(f"polygon({', '.join(relativePoints)});") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment