-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03 Draw Circle In Glyph.py
57 lines (46 loc) · 1.23 KB
/
03 Draw Circle In Glyph.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
53
54
55
56
57
#MenuTitle: 03 Draw Circle In Glyph
from mojo.roboFont import CurrentGlyph
def draw_circle(pen, pt, diameter=50, roundness=0.552):
x, y = pt
radius = 0.5 * diameter
ctrl = 0.5 * diameter * roundness
# Start point (bottom of circle)
pen.moveTo((x, y - radius))
# First quarter circle segment
pen.curveTo(
(x + ctrl, y - radius),
(x + radius, y - ctrl),
(x + radius, y)
)
# Second quarter circle segment
pen.curveTo(
(x + radius, y + ctrl),
(x + ctrl, y + radius),
(x, y + radius)
)
# Third quarter circle segment
pen.curveTo(
(x - ctrl, y + radius),
(x - radius, y + ctrl),
(x - radius, y)
)
# Fourth quarter circle segment
pen.curveTo(
(x - radius, y - ctrl),
(x - ctrl, y - radius),
(x, y - radius)
)
# Close the path (required)
pen.closePath()
if __name__ == "__main__":
g = CurrentGlyph()
g.clear()
p = g.getPen()
# Draw a rectangle
p.moveTo((10, 0))
p.lineTo((540, 0))
p.lineTo((540, 432))
p.lineTo((10, 432))
p.closePath()
# Draw a circle with our circle function
draw_circle(p, (275, 216), 400)