-
-
Save tisimst/99b83d22b9679e8e2d6a3df1f851798d to your computer and use it in GitHub Desktop.
Little defconQt scripting examples
This file contains hidden or 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
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout | |
import random | |
class FuzzDialog(QDialog): | |
def __init__(self, parent=None): | |
super().__init__(parent) | |
layout = QVBoxLayout(self) | |
fuzzBox = QPushButton("Fuzz", self) | |
fuzzBox.clicked.connect(self.glyphFuzzer) | |
layout.addWidget(fuzzBox) | |
self.setLayout(layout) | |
def glyphFuzzer(self): | |
glyph = CurrentGlyph() | |
if glyph is not None and len(glyph): | |
glyph.prepareUndo() | |
for contour in glyph: | |
for point in contour: | |
point.x += random.randrange(-4, 5) | |
point.y += random.randrange(-4, 5) | |
glyph.dirty = True | |
window = FuzzDialog() | |
window.show() |
This file contains hidden or 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
import random | |
font = CurrentFont() | |
for glyph in font: | |
glyph.prepareUndo() | |
color = ",".join(str(random.random()) for _ in range(4)) | |
glyph.lib["public.markColor"] = color |
This file contains hidden or 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
from husl import husl_to_rgb | |
import random | |
font = CurrentFont() | |
golden_ratio_conjugate = 0.618033988749895 | |
h = random.random() | |
minS = random.uniform(30, 70) | |
maxS = minS + 30 | |
minL = random.uniform(50, 70) | |
maxL = minL + 20 | |
print(minS, minL) | |
for glyph in font: | |
glyph.prepareUndo() | |
h = (h + golden_ratio_conjugate) % 1 | |
hue = 360 * h | |
sat = random.uniform(minS, maxS) | |
lum = random.uniform(minL, maxL) | |
col = husl_to_rgb(hue, sat, lum) + [1] | |
color = ",".join(str(c) for c in col) | |
glyph.lib["public.markColor"] = color |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment