From 0f1d1747978c7c9c230b8f6bb13b72f787f15acb Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 01 Nov 2012 13:42:52 +0000 Subject: use float to store internal turtle position and heading --- diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index fb42422..4b8e974 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -217,9 +217,9 @@ class TurtleGraphics: self.tw.active_turtle.set_gray(100) self.tw.active_turtle.set_pen_size(5) self.tw.active_turtle.reset_shapes() - self.seth(0, share) + self.seth(0.0, share) self.setpen(False, share) - self.setxy(0, 0, share) + self.setxy(0.0, 0.0, share) self.setpen(True, share) self.tw.active_turtle.hide() self.set_turtle(self.tw.default_turtle_name) @@ -686,11 +686,10 @@ class TurtleGraphics: x, y = self.turtle_to_screen_coordinates(self.xcor, self.ycor) if self.tw.interactive_mode: self.tw.active_turtle.move( - (int(self.cx + x - self.tw.active_turtle.spr.rect.width / 2.), - int(self.cy + y - self.tw.active_turtle.spr.rect.height / 2.)) - ) + (self.cx + x - self.tw.active_turtle.spr.rect.width / 2., + self.cy + y - self.tw.active_turtle.spr.rect.height / 2.)) else: - self.tw.active_turtle.move((int(self.cx + x), int(self.cy + y))) + self.tw.active_turtle.move(self.cx + x, self.cy + y) def get_color_index(self, r, g, b, a=0): ''' Find the closest palette entry to the rgb triplet ''' @@ -753,8 +752,8 @@ class TurtleGraphics: if k not in self.tw.turtles.dict: # if it is a new turtle, start it in the center of the screen self.tw.active_turtle = self.tw.turtles.get_turtle(k, True, colors) - self.seth(0, False) - self.setxy(0, 0, False, pendown=False) + self.seth(0.0, False) + self.setxy(0.0, 0.0, False, pendown=False) self.tw.active_turtle.set_pen_state(True) elif colors is not None: self.tw.active_turtle = self.tw.turtles.get_turtle(k, False) diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py index c70f379..e3d6e39 100644 --- a/TurtleArt/taturtle.py +++ b/TurtleArt/taturtle.py @@ -112,14 +112,14 @@ class Turtle: def __init__(self, turtles, key, turtle_colors=None): """ The turtle is not a block, just a sprite with an orientation """ - self.x = 0 - self.y = 0 + self.x = 0.0 + self.y = 0.0 self.hidden = False self.shapes = [] self.custom_shapes = False self.type = 'turtle' self.name = key - self.heading = 0 + self.heading = 0.0 self.pen_shade = 50 self.pen_color = 0 self.pen_gray = 100 @@ -190,7 +190,7 @@ class Turtle: if n != 1: debug_output("%d images passed to set_shapes: ignoring" % (n), self.tw.running_sugar) - if self.heading == 0: # rotate the shapes + if self.heading == 0.0: # rotate the shapes images = [] w, h = shapes[0].get_width(), shapes[0].get_height() nw = nh = int(sqrt(w * w + h * h)) @@ -265,18 +265,16 @@ class Turtle: self.move((self.x, self.y)) self.set_heading(self.heading) if self.label_block is not None: - self.label_block.spr.move((self.x + self.label_xy[0], - self.y + self.label_xy[1])) self.label_block.spr.set_layer(TURTLE_LAYER + 1) def move(self, pos): """ Move the turtle. """ - self.x, self.y = int(pos[0]), int(pos[1]) + self.x, self.y = pos[0], pos[1] if not self.hidden and self.spr is not None: - self.spr.move(pos) + self.spr.move((int(pos[0]), int(pos[1]))) if self.label_block is not None: - self.label_block.spr.move((pos[0] + self.label_xy[0], - pos[1] + self.label_xy[1])) + self.label_block.spr.move((int(pos[0] + self.label_xy[0]), + int(pos[1] + self.label_xy[1]))) return(self.x, self.y) def get_name(self): diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index b3896e4..1d1b62c 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -2275,10 +2275,10 @@ class TurtleArtWindow(): self.active_turtle = None else: self._move_turtle( - int(tx - self.canvas.width / 2. + \ - self.active_turtle.spr.rect.width / 2.), - int(self.canvas.height / 2. - ty - \ - self.active_turtle.spr.rect.height / 2.)) + tx - self.canvas.width / 2. + \ + self.active_turtle.spr.rect.width / 2., + self.canvas.height / 2. - ty - \ + self.active_turtle.spr.rect.height / 2.) self.selected_turtle = None if self.active_turtle is None: self.canvas.set_turtle(self.default_turtle_name) -- cgit v0.9.1