1 from pyglet
.gl
import *
2 from plot_mode_base
import PlotModeBase
3 from sympy
.core
.basic
import S
4 from util
import scale_value
, scale_value_list
5 #from time import sleep
7 class PlotCurve(PlotModeBase
):
9 style_override
= 'wireframe'
11 def _on_calculate_verts(self
):
12 self
.t_interval
= self
.intervals
[0]
13 self
.t_set
= list(self
.t_interval
.frange())
14 self
.bounds
= [ [S
.Infinity
,-S
.Infinity
,0],[S
.Infinity
,-S
.Infinity
,0],[S
.Infinity
,-S
.Infinity
,0] ]
15 evaluate
= self
._get
_evaluator
()
17 self
._calculating
_verts
_pos
= 0.0
18 self
._calculating
_verts
_len
= float(self
.t_interval
.v_len
)
23 try: _e
= evaluate(t
) # calculate vertex
25 if _e
is not None: # update bounding box
26 for axis
in xrange(3):
27 b
[axis
][0] = min([b
[axis
][0], _e
[axis
]])
28 b
[axis
][1] = max([b
[axis
][1], _e
[axis
]])
30 self
._calculating
_verts
_pos
+= 1.0
32 for axis
in xrange(3):
33 b
[axis
][2] = b
[axis
][1] - b
[axis
][0]
34 if b
[axis
][2] == 0.0: b
[axis
][2] = 1.0
36 self
.push_wireframe(self
.draw_verts(False))
38 def _on_calculate_cverts(self
):
39 if not self
.verts
or not self
.color
: return
40 def set_work_len(n
): self
._calculating
_cverts
_len
= float(n
)
41 def inc_work_pos(): self
._calculating
_cverts
_pos
+= 1.0
42 set_work_len(1); self
._calculating
_cverts
_pos
= 0
43 self
.cverts
= self
.color
.apply_to_curve(self
.verts
, self
.t_set
, set_len
=set_work_len
, inc_pos
=inc_work_pos
)
44 self
.push_wireframe(self
.draw_verts(True))
46 def calculate_one_cvert(self
, t
):
48 return self
.color(vert
[0], vert
[1], vert
[2],
51 def draw_verts(self
, use_cverts
):
53 glBegin(GL_LINE_STRIP
)
54 for t
in xrange( len(self
.t_set
) ):
58 glBegin(GL_LINE_STRIP
)
62 if c
is None: c
= (0, 0, 0)
64 else: glColor3f(*self
.default_wireframe_color
)