-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSandblast.py
52 lines (39 loc) · 1.22 KB
/
Sandblast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#MenuTitle: Sandblast
# -*- coding: utf-8 -*-
__doc__="""
Drill randomly-sized holes in the glyph
"""
import random
import math
from Foundation import NSMakePoint
layer = Glyphs.font.selectedLayers[0] # current layer
left, bottom = layer.bounds.origin.x, layer.bounds.origin.y
width, height = layer.bounds.size.width, layer.bounds.size.height
dust = []
f = layer.completeBezierPath
points = 1000
while points:
x = random.randrange(left, left+width)
y = random.randrange(bottom, bottom+height)
if not f.containsPoint_(NSMakePoint(x,y)):
continue
sides = random.randrange(15,30)
p = GSPath()
angle = math.radians(360/sides)
for i in range(sides):
p.nodes.append(GSNode( (x, y), LINE))
delta = abs(random.gauss(5,20) / float(sides))
x = x + math.cos(i * angle) * (random.random() + delta)
y = y + math.sin(i * angle) * (random.random() + delta)
points = points - 1
p.closed = True
if p.direction == layer.paths[0].direction:
p.reverse()
dust.append(p)
GSPathOperator = objc.lookUpClass("GSPathOperator")
pathOp = GSPathOperator.alloc().init()
inpaths = list(layer.paths)
pathOp.subtractPaths_from_error_( dust, inpaths, None )
layer.paths.extend(inpaths)
# layer.paths.extend(dust)
layer.correctPathDirection()