Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created April 23, 2019 14:24
Show Gist options
  • Select an option

  • Save typemytype/d699cdc8b08c44b4f8584ee5d09373f8 to your computer and use it in GitHub Desktop.

Select an option

Save typemytype/d699cdc8b08c44b4f8584ee5d09373f8 to your computer and use it in GitHub Desktop.
import defcon
glyph = defcon.Glyph()
pen = glyph.getPen()
pen.moveTo((76, 102))
pen.qCurveTo(
(168, 94),
(248, 126),
(296, 198),
(350, 252)
)
pen.lineTo((302, 290))
pen.qCurveTo(
(270, 224),
(224, 170),
(116, 138),
(76, 152)
)
pen.closePath()
pen.moveTo((156, 258))
pen.qCurveTo(
(156, 194),
(190, 134),
(246, 84),
(350, 52)
)
pen.lineTo((366, 98))
pen.qCurveTo(
(296, 126),
(252, 170),
(224, 224),
(218, 282)
)
pen.closePath()
path = BezierPath()
glyph.draw(path)
fill(None)
stroke(0)
drawPath(path)
s = 7
stroke(None)
for contour in glyph:
for point in contour:
if point.segmentType:
fill(1, 0, 1, .3)
else:
fill(0, 1, 0, .3)
oval(point.x-s, point.y-s, s*2, s*2)
from booleanOperations.booleanOperationManager import BooleanOperationManager
result = defcon.Glyph()
m = BooleanOperationManager()
m.union(list(glyph), result.getPointPen())
resultPath = BezierPath()
result.draw(resultPath)
stroke(1, 0, 0)
fill(None)
drawPath(resultPath)
s = 3
stroke(1)
for contour in result:
for point in contour:
if point.segmentType:
fill(1, 0, 1)
else:
fill(0, 1, 0)
oval(point.x-s, point.y-s, s*2, s*2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment