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 get_window_physical(self, fx, fy, step=False): """ Convert logical to physical coordinates. """ if self.window: scalex, scaley, offsetx, offsety = self.window if step: fx0, fy0 = self.get_window_logical(*self.last_point) else: fx0, fy0 = fp.Single.zero.copy(), fp.Single.zero.copy() x = fp.add(offsetx, fp.mul(fx0.iadd(fx), scalex)).round_to_int() y = fp.add(offsety, fp.mul(fy0.iadd(fy), scaley)).round_to_int() else: x, y = self.last_point if step else (0, 0) x += fx.round_to_int() y += fy.round_to_int() # overflow check if x < -0x8000 or y < -0x8000 or x > 0x7fff or y > 0x7fff: raise error.RunError(error.OVERFLOW) return x, y