def render(self): if self.m_field and self.m_arcpoints and self.m_arcindex and self.m_color: # e.g., self.m_arcpoints = [(10,5),(15,5),(15,10),(15,15),(10,15),(5,15),(5,10)] # e.g., self.m_arcindex = [(0,1,2,3),(3,4,5,6)] #print "self.m_arcpoints = ",self.m_arcpoints #print "self.m_arcindex = ",self.m_arcindex for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] (points,index) = curves.cubic_spline(p0,p1,p2,p3,CURVE_SEGS) if self.m_solid: points.append(self.m_center) nxlast_pt = len(points)-2 last_pt = len(points)-1 xtra_index = [nxlast_pt,last_pt,last_pt,0] index = index + xtra_index self.m_points.append(points) self.m_index.append(index)
def render(self): if self.m_field and self.m_arcpoints and self.m_arcindex and self.m_color: # e.g., self.m_arcpoints = [(10,5),(15,5),(15,10),(15,15),(10,15),(5,15),(5,10)] # e.g., self.m_arcindex = [(0,1,2,3),(3,4,5,6)] if dbug.LEV & dbug.GRAPH: print "Graph:render:self.m_arcpoints = ",self.m_arcpoints if dbug.LEV & dbug.GRAPH: print "Graph:render:self.m_arcindex = ",self.m_arcindex for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2,3) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] # if this is a straight line, don't chop into cubicSplines if p0[0] == p1[0] == p2[0] == p3[0] or \ p0[1] == p1[1] == p2[1] == p3[1]: points = [p0,p1,p2,p3] index = [0,1,1,2,2,3] # TODO: convert CURVE_SEGS into a passable parameter, so in the # case of a straight line, we pass t=1 so it makes ONE slice else: (points,index) = curves.cubic_spline(p0,p1,p2,p3,CURVE_SEGS) self.m_points.append(points) self.m_index.append(index)
def draw(self): """Draw a line, which is actually a path made up of cubicsplines. We come into this routine with the shape already calculated, and the data in the following form: a list of points: self.m_arcpoints = [(10,5),(15,5),(15,10),(15,15),(10,15),(5,15),(5,10)] an index of fourples that describe an arc (cubicspline) self.m_arcindex = [(0,1,2,3),(3,4,5,6)] The screen engine wants these arcs divded up into line segments The laser engine wants these arcs divied up into OSC messages """ if self.m_p0 and self.m_p1: self.render() if self.m_field and self.m_arcpoints and self.m_arcindex and self.m_color: if GRAPHMODES & GRAPHOPTS['screen']: # The screen engine, pyglet, wants output in this form # a list of points # points = [(10.0,10.0), (20.0,0), (-10.0,10.0), etc] # an index into points describing contiguous line segments # index = [(1,2), (2, 3), (3,4), etc] # for each arc in the circle, convert to line segments if dbug.LEV & dbug.GRAPH: print "Graph:draw:self.m_arcpoints = ", self.m_arcpoints if dbug.LEV & dbug.GRAPH: print "Graph:draw:self.m_arcindex = ", self.m_arcindex for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2,3) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] # if this is a straight line, don't chop into cubicSplines #TODO: Replace with colinear test if p0[0] == p1[0] == p2[0] == p3[0] or \ p0[1] == p1[1] == p2[1] == p3[1]: points = [p0, p1, p2, p3] index = [0, 1, 1, 2, 2, 3] # TODO: convert CURVE_SEGS into a passable parameter, so in the # case of a straight line, we pass t=1 so it makes ONE slice else: (points, index) = curves.cubic_spline(p0, p1, p2, p3, CURVE_SEGS) self.m_points.append(points) self.m_index.append(index) if dbug.LEV & dbug.GRAPH: print "Graph:draw:self.m_points =", self.m_points if dbug.LEV & dbug.GRAPH: print "Graph:draw:index:", self.m_index # now, for each segment, output a line to pyglet for i in range(len(self.m_index)): points = self.m_points[i] if dbug.LEV & dbug.GRAPH: print "Graph:draw:points =", points scaled_pts = self.m_field.rescale_pt2screen(points) if dbug.LEV & dbug.GRAPH: print "Graph:draw:screen:scaled_points =", scaled_pts index = self.m_index[i] pyglet.gl.glColor3f(self.m_color[0], self.m_color[1], self.m_color[2]) pyglet.graphics.draw_indexed( len(scaled_pts), pyglet.gl.GL_LINES, index, ('v2i', tuple(chain(*scaled_pts))), ) if GRAPHMODES & GRAPHOPTS['osc']: # the laser engine wants output of this form: # /laser/bezier/cubic ffffffff # we send an OSC message like this: # self.m_field.m_osc_laser.send( OSCMessage("/user/1", [1.0, 2.0, 3.0 ] ) ) #scaled_pts = self.m_field.rescale_pt2vector(points) if dbug.LEV & dbug.GRAPH: print "Line:OSC to laser:", OSCPATH['graph_color'], \ [self.m_color[0],self.m_color[1],self.m_color[2]] self.m_field.m_osc.send_laser( OSCPATH['graph_color'], [self.m_color[0], self.m_color[1], self.m_color[2]]) for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] if dbug.LEV & dbug.GRAPH: print "Line:OSC to laser:", OSCPATH['graph_cubic'], \ [p0[0], p0[1], p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]] self.m_field.m_osc.send_laser(OSCPATH['graph_cubic'], [ p0[0], p0[1], p1[0], p1[1], p2[0], p2[1], p3[0], p3[1] ])
def draw(self): """Draw a circle. We come into this routine with the shape already calculated, and the data in the following form: a list of points: self.m_arcpoints = [(10,5),(15,5),(15,10),(15,15),(10,15),(5,15),(5,10)] an index of fourples that describe an arc (cubicspline) self.m_arcindex = [(0,1,2,3),(3,4,5,6)] The screen engine wants these arcs divded up into line segments The laser engine wants these arcs divied up into OSC messages """ if self.m_center and self.m_radius: self.render() if self.m_field and self.m_arcpoints and self.m_arcindex and self.m_color: if GRAPHMODES & GRAPHOPTS['screen']: # The screen engine, pyglet, wants output in this form # a list of points # points = [(10.0,10.0), (20.0,0), (-10.0,10.0), etc] # an index into points describing contiguous line segments # index = [(1,2), (2, 3), (3,4), etc] # for each arc in the circle, convert to line segments for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] (points, index) = curves.cubic_spline(p0, p1, p2, p3, CURVE_SEGS) if self.m_solid: points.append(self.m_center) nxlast_pt = len(points) - 2 last_pt = len(points) - 1 xtra_index = [nxlast_pt, last_pt, last_pt, 0] index = index + xtra_index self.m_points.append(points) self.m_index.append(index) # now, for each segment, output a line to pyglet for i in range(len(self.m_index)): points = self.m_points[i] if dbug.LEV & dbug.GRAPH: print "Circle:draw:Points =", points scaled_pts = self.m_field.rescale_pt2screen(points) if dbug.LEV & dbug.GRAPH: print "Circle:draw:screen:scaled_pts =", scaled_pts index = self.m_index[i] pyglet.gl.glColor3f(self.m_color[0], self.m_color[1], self.m_color[2]) if not self.m_solid: pyglet.graphics.draw_indexed( len(scaled_pts), pyglet.gl.GL_LINES, index, ('v2i', tuple(chain(*scaled_pts))), ) else: pyglet.graphics.draw_indexed( len(scaled_pts), pyglet.gl.GL_POLYGON, index, ('v2i', tuple(chain(*scaled_pts))), ) if GRAPHMODES & GRAPHOPTS['osc']: # the laser engine wants output of this form: # /laser/bezier/cubic ffffffff # we send an OSC message like this: # self.m_field.m_osc_laser.send( OSCMessage("/user/1", [1.0, 2.0, 3.0 ] ) ) #scaled_pts = self.m_field.rescale_pt2vector(points) #if dbug.LEV & dbug.GRAPH: print "Circle:draw:vector:scaled_pts =",scaled_pts if dbug.LEV & dbug.GRAPH: print "Circle:OSC to laser:", OSCPATH['graph_color'], \ [self.m_color[0],self.m_color[1],self.m_color[2]] self.m_field.m_osc.send_laser( OSCPATH['graph_color'], [self.m_color[0], self.m_color[1], self.m_color[2]]) for i in range(len(self.m_arcindex)): # e.g., self.m_arcindex[i] = (0,1,2) p0 = self.m_arcpoints[self.m_arcindex[i][0]] p1 = self.m_arcpoints[self.m_arcindex[i][1]] p2 = self.m_arcpoints[self.m_arcindex[i][2]] p3 = self.m_arcpoints[self.m_arcindex[i][3]] if dbug.LEV & dbug.GRAPH: print "Circle:OSC to laser:", OSCPATH['graph_cubic'], \ [p0[0], p0[1], p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]] self.m_field.m_osc.send_laser(OSCPATH['graph_cubic'], [ p0[0], p0[1], p1[0], p1[1], p2[0], p2[1], p3[0], p3[1] ])