def paintLine(points, numsteps=None, **kwargs): '''Paint a line with current brush :: set_brush("mybrush.png", 10) paintLine((0, 0, 20, 50)) paintLine((1, 2, 1, 5, 4, 6, 8, 7)) ''' if not __brush_texture: pymt.pymt_logger.warning('Graphx: No brush set to paint line, abort') return if len(points) % 2 == 1: raise Exception('Points list must be a pair length number (not impair)') kwargs.setdefault('sfactor', GL_SRC_ALPHA) kwargs.setdefault('dfactor', GL_ONE_MINUS_SRC_ALPHA) blending = GlBlending(sfactor=kwargs.get('sfactor'), dfactor=kwargs.get('dfactor')) with DO(blending, gx_enable(GL_POINT_SPRITE_ARB), gx_enable(__brush_texture.target)): # prepare env set_texture(__brush_texture.id, target=__brush_texture.target) glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE) glPointSize(__brush_size) # initialize outputList outputList = [] # extract 4 points each 2 points for x1, y1, x2, y2 in zip(points[::2], points[1::2], points[2::2], points[3::2]): # calculate vector and distance dx, dy = x2 - x1, y2 - y1 dist = sqrt(dx * dx + dy * dy) # determine step steps = numsteps if steps is None: steps = max(1, int(dist) / 4) # construct pointList for i in xrange(steps): outputList.extend([x1 + dx * (float(i) / steps), y1 + dy * (float(i) / steps)]) # draw ! if len(outputList) < 2: return with gx_begin(GL_POINTS): for x, y in zip(outputList[::2], outputList[1::2]): glVertex2f(x, y)
def draw_filled_path(self): for style, points in self.filled_path: with gx_begin(style): for x, y in zip(points[::2], points[1::2]): glVertex2f(x, y)