def get_window_logical(self, x, y): """ Convert physical to logical coordinates. """ x, y = fp.Single.from_int(x), fp.Single.from_int(y) if self.window: scalex, scaley, offsetx, offsety = self.window return (fp.div(fp.sub(x, offsetx), scalex), fp.div(fp.sub(y, offsety), scaley)) else: return x, y
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
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
def set_window(self, fx0, fy0, fx1, fy1, cartesian=True): """ Set the logical coordinate window (WINDOW). """ if fy0.gt(fy1): fy0, fy1 = fy1, fy0 if fx0.gt(fx1): fx0, fx1 = fx1, fx0 if cartesian: fy0, fy1 = fy1, fy0 left, top, right, bottom = self.get_view() x0, y0 = fp.Single.zero, fp.Single.zero x1, y1 = fp.Single.from_int(right-left), fp.Single.from_int(bottom-top) scalex = fp.div(fp.sub(x1, x0), fp.sub(fx1,fx0)) scaley = fp.div(fp.sub(y1, y0), fp.sub(fy1,fy0)) offsetx = fp.sub(x0, fp.mul(fx0,scalex)) offsety = fp.sub(y0, fp.mul(fy0,scaley)) self.window = scalex, scaley, offsetx, offsety self.window_bounds = fx0, fy0, fx1, fy1, cartesian
def set_window(self, fx0, fy0, fx1, fy1, cartesian=True): """ Set the logical coordinate window (WINDOW). """ if fy0.gt(fy1): fy0, fy1 = fy1, fy0 if fx0.gt(fx1): fx0, fx1 = fx1, fx0 if cartesian: fy0, fy1 = fy1, fy0 left, top, right, bottom = self.get_view() x0, y0 = fp.Single.zero, fp.Single.zero x1, y1 = fp.Single.from_int(right - left), fp.Single.from_int(bottom - top) scalex = fp.div(fp.sub(x1, x0), fp.sub(fx1, fx0)) scaley = fp.div(fp.sub(y1, y0), fp.sub(fy1, fy0)) offsetx = fp.sub(x0, fp.mul(fx0, scalex)) offsety = fp.sub(y0, fp.mul(fy0, scaley)) self.window = scalex, scaley, offsetx, offsety self.window_bounds = fx0, fy0, fx1, fy1, cartesian