Skip to content

Instantly share code, notes, and snippets.

@adrientetar
Last active March 1, 2017 16:56
Show Gist options
  • Save adrientetar/46368fd9ac693e6c3a4f to your computer and use it in GitHub Desktop.
Save adrientetar/46368fd9ac693e6c3a4f to your computer and use it in GitHub Desktop.
Little defconQt scripting examples
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()
import random
font = CurrentFont()
for glyph in font:
glyph.prepareUndo()
color = ",".join(str(random.random()) for _ in range(4))
glyph.lib["public.markColor"] = color
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