Debian Codegraph @

third_party/spiro/x3/pyrex/beztest.py

raw symbols SCIP
1 import x3
2 from math import *
3
4 def my_callback(cmd, what, arg, more):
5 print cmd, what, arg
6
7 class bez:
8 def __init__(self):
9 self.coords = [(10, 10), (200, 10), (300, 200), (400, 100)]
10 self.hit = None
11 def draw(self, dc):
12 coords = self.coords
13 dc.setrgba(0, 0, 0.5, 1)
14 dc.moveto(coords[0][0], coords[0][1])
15 dc.curveto(coords[1][0], coords[1][1], coords[2][0], coords[2][1],
16 coords[3][0], coords[3][1])
17 dc.stroke()
18 dc.setrgba(0, 0.5, 0, 0.5)
19 dc.moveto(coords[0][0], coords[0][1])
20 dc.lineto(coords[1][0], coords[1][1])
21 dc.stroke()
22 dc.moveto(coords[2][0], coords[2][1])
23 dc.lineto(coords[3][0], coords[3][1])
24 dc.stroke()
25 dc.setrgba(1, 0, 0, .5)
26 for x, y in coords:
27 dc.rectangle(x - 3, y - 3, 6, 6)
28 dc.fill()
29 def mouse(self, button, mods, x, y):
30 if button == 1:
31 for i in range(4):
32 if hypot(x - self.coords[i][0], y - self.coords[i][1]) < 4:
33 self.hit = i
34 elif button == -1:
35 self.hit = None
36 elif self.hit != None:
37 self.coords[self.hit] = (x, y)
38 self.view.dirty()
39
40 win = x3.window(0, "beztest", my_callback)
41
42 x3.view(win, 259, bez())
43
44 x3.main()