MCPcopy Create free account
hub / github.com/coldtype/coldtype / NextDrawPen

Class NextDrawPen

examples/axidraw/nextdraw.py:21–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20
21class NextDrawPen(BasePen):
22 def __init__(self, dat, page, move_delay=0):
23 super().__init__(None)
24 self.dat = dat
25 self.page = page
26 self.ad = None
27 self.move_delay = move_delay
28 #dat.replay(self)
29 self.last_moveTo = None
30
31 def _moveTo(self, p):
32 self.last_moveTo = p
33 time.sleep(self.move_delay)
34 self.ad.moveto(*p)
35 time.sleep(self.move_delay)
36
37 def _lineTo(self, p):
38 time.sleep(self.move_delay)
39 self.ad.lineto(*p)
40
41 def _curveToOne(self, p1, p2, p3):
42 print("! CANNOT CURVE !")
43
44 def _qCurveToOne(self, p1, p2):
45 print("! CANNOT CURVE !")
46
47 def _closePath(self):
48 # can this work?
49 if self.last_moveTo:
50 self.ad.lineto(*self.last_moveTo)
51
52 def draw(self,
53 scale=0.01,
54 cm=False,
55 ad=None,
56 move_delay=0,
57 zero=True,
58 ):
59
60 self.dat.scale(scale, point=Point(0, 0))
61 page = self.page.scale(scale)
62 bounds = self.dat.bounds()
63
64 limits = Rect(0, 0, 11, 8.5)
65 if cm:
66 limits = limits.scale(2.54)
67
68 def small_enough(r):
69 return (r.mnx >= 0
70 and r.mny >= 0
71 and r.mxx <= limits.w
72 and r.mxy <= limits.h)
73
74 if small_enough(page) and small_enough(bounds):
75 print("Drawing!")
76 else:
77 print("Too big!", page, bounds)
78 return False

Callers 1

walkerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected