Beispiel #1
0
 def circle(self, lcoord, r, start, stop, c, aspect):
     """ Draw a circle, ellipse, arc or sector (CIRCLE). """
     x0, y0 = self.view_coords(*self.get_window_physical(*lcoord))
     c = self.get_attr_index(c)
     if aspect == None:
         aspect = fp.div(
             fp.Single.from_int(self.screen.mode.pixel_aspect[0]),
             fp.Single.from_int(self.screen.mode.pixel_aspect[1]),
         )
     if aspect.equals(aspect.one):
         rx, _ = self.get_window_scale(r, fp.Single.zero)
         ry = rx
     elif aspect.gt(aspect.one):
         _, ry = self.get_window_scale(fp.Single.zero, r)
         rx = fp.div(r, aspect).round_to_int()
     else:
         rx, _ = self.get_window_scale(r, fp.Single.zero)
         ry = fp.mul(r, aspect).round_to_int()
     start_octant, start_coord, start_line = -1, -1, False
     if start:
         start = fp.unpack(vartypes.pass_single_keep(start))
         start_octant, start_coord, start_line = get_octant(start, rx, ry)
     stop_octant, stop_coord, stop_line = -1, -1, False
     if stop:
         stop = fp.unpack(vartypes.pass_single_keep(stop))
         stop_octant, stop_coord, stop_line = get_octant(stop, rx, ry)
     if aspect.equals(aspect.one):
         self.draw_circle(x0, y0, rx, c, start_octant, start_coord, start_line, stop_octant, stop_coord, stop_line)
     else:
         startx, starty, stopx, stopy = -1, -1, -1, -1
         if start != None:
             startx = abs(fp.mul(fp.Single.from_int(rx), fp.cos(start)).round_to_int())
             starty = abs(fp.mul(fp.Single.from_int(ry), fp.sin(start)).round_to_int())
         if stop != None:
             stopx = abs(fp.mul(fp.Single.from_int(rx), fp.cos(stop)).round_to_int())
             stopy = abs(fp.mul(fp.Single.from_int(ry), fp.sin(stop)).round_to_int())
         self.draw_ellipse(
             x0,
             y0,
             rx,
             ry,
             c,
             start_octant / 2,
             startx,
             starty,
             start_line,
             stop_octant / 2,
             stopx,
             stopy,
             stop_line,
         )
     self.last_attr = c
     self.last_point = x0, y0
Beispiel #2
0
 def circle(self, lcoord, r, start, stop, c, aspect):
     """ Draw a circle, ellipse, arc or sector (CIRCLE). """
     x0, y0 = self.view_coords(*self.get_window_physical(*lcoord))
     c = self.get_attr_index(c)
     if aspect is None:
         aspect = fp.div(
             fp.Single.from_int(self.screen.mode.pixel_aspect[0]),
             fp.Single.from_int(self.screen.mode.pixel_aspect[1]))
     if aspect.equals(aspect.one):
         rx, _ = self.get_window_scale(r, fp.Single.zero)
         ry = rx
     elif aspect.gt(aspect.one):
         _, ry = self.get_window_scale(fp.Single.zero, r)
         rx = fp.div(r, aspect).round_to_int()
     else:
         rx, _ = self.get_window_scale(r, fp.Single.zero)
         ry = fp.mul(r, aspect).round_to_int()
     start_octant, start_coord, start_line = -1, -1, False
     if start:
         start = fp.unpack(vartypes.pass_single_keep(start))
         start_octant, start_coord, start_line = get_octant(start, rx, ry)
     stop_octant, stop_coord, stop_line = -1, -1, False
     if stop:
         stop = fp.unpack(vartypes.pass_single_keep(stop))
         stop_octant, stop_coord, stop_line = get_octant(stop, rx, ry)
     if aspect.equals(aspect.one):
         self.draw_circle(x0, y0, rx, c, start_octant, start_coord,
                          start_line, stop_octant, stop_coord, stop_line)
     else:
         startx, starty, stopx, stopy = -1, -1, -1, -1
         if start is not None:
             startx = abs(
                 fp.mul(fp.Single.from_int(rx),
                        fp.cos(start)).round_to_int())
             starty = abs(
                 fp.mul(fp.Single.from_int(ry),
                        fp.sin(start)).round_to_int())
         if stop is not None:
             stopx = abs(
                 fp.mul(fp.Single.from_int(rx),
                        fp.cos(stop)).round_to_int())
             stopy = abs(
                 fp.mul(fp.Single.from_int(ry),
                        fp.sin(stop)).round_to_int())
         self.draw_ellipse(x0, y0, rx, ry, c, start_octant / 2, startx,
                           starty, start_line, stop_octant / 2, stopx,
                           stopy, stop_line)
     self.last_attr = c
     self.last_point = x0, y0
Beispiel #3
0
 def draw_step(self, x0, y0, sx, sy, plot, goback):
     """ Make a DRAW step, drawing a line and reurning if requested. """
     scale = self.draw_scale
     rotate = self.draw_angle
     aspect = self.screen.mode.pixel_aspect
     yfac = aspect[1] / (1.*aspect[0])
     x1 = (scale*sx) / 4
     y1 = (scale*sy) / 4
     if rotate == 0 or rotate == 360:
         pass
     elif rotate == 90:
         x1, y1 = int(y1*yfac), -int(x1//yfac)
     elif rotate == 180:
         x1, y1 = -x1, -y1
     elif rotate == 270:
         x1, y1 = -int(y1*yfac), int(x1//yfac)
     else:
         fx, fy = fp.Single.from_int(x1), fp.Single.from_int(y1)
         phi = fp.mul(fp.Single.from_int(rotate), deg_to_rad)
         sinr, cosr = fp.sin(phi), fp.cos(phi)
         fxfac = fp.div(fp.Single.from_int(aspect[0]), fp.Single.from_int(aspect[1]))
         fx, fy = fp.add(fp.mul(cosr,fx), fp.div(fp.mul(sinr,fy), fxfac)), fp.mul(fp.sub(fp.mul(cosr,fy), fxfac), fp.mul(sinr,fx))
         x1, y1 = fx.round_to_int(), fy.round_to_int()
     y1 += y0
     x1 += x0
     if plot:
         self.draw_line(x0, y0, x1, y1, self.last_attr)
     self.last_point = x1, y1
     if goback:
         self.last_point = x0, y0
Beispiel #4
0
 def draw_step(self, x0, y0, sx, sy, plot, goback):
     """ Make a DRAW step, drawing a line and reurning if requested. """
     scale = self.draw_scale
     rotate = self.draw_angle
     aspect = self.screen.mode.pixel_aspect
     yfac = aspect[1] / (1. * aspect[0])
     x1 = (scale * sx) / 4
     y1 = (scale * sy) / 4
     if rotate == 0 or rotate == 360:
         pass
     elif rotate == 90:
         x1, y1 = int(y1 * yfac), -int(x1 // yfac)
     elif rotate == 180:
         x1, y1 = -x1, -y1
     elif rotate == 270:
         x1, y1 = -int(y1 * yfac), int(x1 // yfac)
     else:
         fx, fy = fp.Single.from_int(x1), fp.Single.from_int(y1)
         phi = fp.mul(fp.Single.from_int(rotate), deg_to_rad)
         sinr, cosr = fp.sin(phi), fp.cos(phi)
         fxfac = fp.div(fp.Single.from_int(aspect[0]),
                        fp.Single.from_int(aspect[1]))
         fx, fy = fp.add(fp.mul(cosr, fx),
                         fp.div(fp.mul(sinr, fy), fxfac)), fp.mul(
                             fp.sub(fp.mul(cosr, fy), fxfac),
                             fp.mul(sinr, fx))
         x1, y1 = fx.round_to_int(), fy.round_to_int()
     y1 += y0
     x1 += x0
     if plot:
         self.draw_line(x0, y0, x1, y1, self.last_attr)
     self.last_point = x1, y1
     if goback:
         self.last_point = x0, y0
Beispiel #5
0
def get_octant(mbf, rx, ry):
    """ Get the circle octant for a given coordinate. """
    neg = mbf.neg
    if neg:
        mbf.negate()
    octant = 0
    comp = fp.Single.pi4.copy()
    while mbf.gt(comp):
        comp.iadd(fp.Single.pi4)
        octant += 1
        if octant >= 8:
            raise error.RunError(error.IFC)
    if octant in (0, 3, 4, 7):
        # running var is y
        coord = abs(fp.mul(fp.Single.from_int(ry), fp.sin(mbf)).round_to_int())
    else:
        # running var is x
        coord = abs(fp.mul(fp.Single.from_int(rx), fp.cos(mbf)).round_to_int())
    return octant, coord, neg
Beispiel #6
0
def get_octant(mbf, rx, ry):
    """ Get the circle octant for a given coordinate. """
    neg = mbf.neg
    if neg:
        mbf.negate()
    octant = 0
    comp = fp.Single.pi4.copy()
    while mbf.gt(comp):
        comp.iadd(fp.Single.pi4)
        octant += 1
        if octant >= 8:
            raise error.RunError(error.IFC)
    if octant in (0, 3, 4, 7):
        # running var is y
        coord = abs(fp.mul(fp.Single.from_int(ry), fp.sin(mbf)).round_to_int())
    else:
        # running var is x
        coord = abs(fp.mul(fp.Single.from_int(rx), fp.cos(mbf)).round_to_int())
    return octant, coord, neg