chiark / gitweb /
64d4b6cb41c603ca762eb77d40cf93ccda71bdd7
[moebius3.git] / visual
1 #!/usr/bin/python
2
3 from __future__ import print_function
4
5 import signal
6 signal.signal(signal.SIGINT, signal.SIG_DFL)
7
8 from visual import *
9 from bezier import BezierSegment
10 import numpy as np
11 import sys
12
13 scene.width = 1200
14 scene.height = 1200
15 scene.fov = 1E-3
16
17 from moebius import *
18 from moedebug import *
19
20 nv = 20
21 nw = 40
22
23 class Visdebug(BaseVisdebug):
24   def curve(vd, fn, color=color.yellow):
25     # fn(t) => 3-tuple, 3-list, or similar, for t \elem [0,1]
26     ps = [ fn(t) for t in np.linspace(0,1,11) ]
27     #dbg('Visdebug', ps)
28     curve(pos = ps, color=color)
29   def circle(vd, c, axis, **kw):
30     ring(pos=c, axis=axis, radius=np.linalg.norm(axis), thickness=0.005, **kw)
31   def arrow(vd, p, d, **kw):
32     print('arrow %s' % repr(kw), file=sys.stderr)
33     bodge_color = kw.get('color', (1,0,0))
34     try: del kw['color']
35     except KeyError: pass
36     vd.line(p, p+d, color=bodge_color, **kw)
37     vd.circle(p, np.asarray(d) * 0.25, color=bodge_color, **kw)
38   def crashing(vd, msg):
39     print("CRASHING - VISDEBUG", msg, file=sys.stderr)
40     rate(1E-8)
41
42 dbg_file(sys.stderr)
43 vdbg_enable(Visdebug())
44
45 m = Moebius(nv, nw)
46
47 vs = range(0, nv+1)
48 ws = range(0, nw+1)
49
50 #ts = np.linspace(0, 1, 40)
51
52 #thetas = np.linspace(0, tau, 40)
53 #c0 = curve( color=color.red, pos = [ m.edge.point(th) for th in thetas ] )
54 #c1 = curve( color=color.blue, pos = [ m.midline.point(th) for th in thetas ] )
55
56 for vi in range(0, len(vs)):
57   v= vs[vi]
58   c2 = curve( color= (color.blue if vi == int(2*nv/3) else (0,0,0.5)),
59               pos = [ m.point(v,w) for w in ws ] )
60
61 #for w in ws:
62 #  c3 = curve( color=color.blue, pos = [ m.point(v,w) for v in vs ] )
63
64
65 #for v in vs:
66 #  c4 = curve( color=color.blue,
67 #              pos = [ m.point_offset(v,w, 0.1) for w in ws ] )
68
69 #for w in ws:
70 #  c3 = curve( color=(1,0,1), pos = [ m.point_offset(v,w, -0.1) for v in vs ] )
71