(self, x0, y0, x1, y1, attr, pattern=0xffff)
Draw a line between the given physical points.
Draw a line between the given physical points.
Draw a line between the given physical points .
def _draw_line(self, x0, y0, x1, y1, attr, pattern=0xffff):
        """Draw a line between the given physical points."""
        # cut off any out-of-bound coordinates
        x0, y0 = self.graph_view.cutoff_coord(x0, y0)
        x1, y1 = self.graph_view.cutoff_coord(x1, y1)
        if y1 <= y0:
            # work from top to bottom, or from x1,y1 if at the same height. this matters for mask.
            x1, y1, x0, y0 = x0, y0, x1, y1
        # Bresenham algorithm
        dx, dy = abs(x1-x0), abs(y1-y0)
        steep = dy > dx
        if steep:
            x0, y0, x1, y1 = y0, x0, y1, x1
            dx, dy = dy, dx
        sx = 1 if x1 > x0 else -1
        sy = 1 if y1 > y0 else -1
        mask = 0x8000
        line_error = dx // 2
        x, y = x0, y0
        for x in range(x0, x1+sx, sx):
            if pattern & mask != 0:
                if steep:
                    # set point (y, x)
                    self.graph_view[x, y] = attr
                else:
                    self.graph_view[y, x] = attr
            mask >>= 1
            if mask == 0:
                mask = 0x8000
            line_error -= dy
            if line_error < 0:
                y += sy
                line_error += dx
def _draw_line ( self , x0 , y0 , x1 , y1 , attr , pattern = 0xffff ) : # cut off any out-of-bound coordinates x0 , y0 = self . graph_view . cutoff_coord ( x0 , y0 ) x1 , y1 = self . graph_view . cutoff_coord ( x1 , y1 ) if y1 <= y0 : # work from top to bottom, or from x1,y1 if at the same height. this matters for mask. x1 , y1 , x0 , y0 = x0 , y0 , x1 , y1 # Bresenham algorithm dx , dy = abs ( x1 - x0 ) , abs ( y1 - y0 ) steep = dy > dx if steep : x0 , y0 , x1 , y1 = y0 , x0 , y1 , x1 dx , dy = dy , dx sx = 1 if x1 > x0 else - 1 sy = 1 if y1 > y0 else - 1 mask = 0x8000 line_error = dx // 2 x , y = x0 , y0 for x in range ( x0 , x1 + sx , sx ) : if pattern & mask != 0 : if steep : # set point (y, x) self . graph_view [ x , y ] = attr else : self . graph_view [ y , x ] = attr mask >>= 1 if mask == 0 : mask = 0x8000 line_error -= dy if line_error < 0 : y += sy line_error += dx