From cae91fb79822066f07ca5b54034cce8b53654d1a Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 22 Sep 2010 21:38:10 +0000 Subject: refactoring turtle skin scaling (#2353) --- diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index 88a9e5d..9928d51 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -569,7 +569,10 @@ class TurtleGraphics: def move_turtle(self): """ Move the turtle """ x, y = self.width / 2 + int(self.xcor), self.height / 2 - int(self.ycor) - self.tw.active_turtle.move((self.cx + x - 28, self.cy + y - 30)) + self.tw.active_turtle.move((self.cx + x - \ + self.tw.active_turtle.spr.rect.width/2, + self.cy + y - \ + self.tw.active_turtle.spr.rect.height/2,)) def invalt(self, x, y, w, h): """ Mark a region for refresh """ diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 3a5af72..10c1e69 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -179,6 +179,7 @@ HIT_RED = "#F80000" HIT_GREEN = "#00F000" HIDE_WHITE = "#F8F8F8" SHOW_WHITE = "#F0F0F0" +DEFAULT_SCALE = 33 # # Block-style definitions @@ -1090,4 +1091,5 @@ MACROS = { [20, 'sandwichbottom', 0, 0, [18, None]]], 'reskin': [[0, 'skin', 0, 0, [None, 1, None]], - [1, 'journal', 0, 0, [0, None]]] } + [1, 'journal', 0, 0, [0, None]]] + } diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 0af7110..b44116e 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -33,7 +33,8 @@ try: except: pass -from taconstants import PALETTES, PALETTE_NAMES, TAB_LAYER, BLACK, WHITE +from taconstants import PALETTES, PALETTE_NAMES, TAB_LAYER, BLACK, WHITE, \ + DEFAULT_SCALE, ICON_SIZE from tagplay import play_audio, play_movie_from_file, stop_media from tajail import myfunc, myfunc_import from tautils import get_pixbuf_from_journal, movie_media_type, convert, \ @@ -245,8 +246,6 @@ def millis(): return int(clock()*1000) -_DEFAULT_SCALE = 33 - """ A class for parsing Logo Code """ @@ -423,7 +422,7 @@ class LogoCode: self.body_height = int((self.tw.canvas.height/40)*self.tw.scale) self.bullet_height = int((self.tw.canvas.height/30)*self.tw.scale) - self.scale = _DEFAULT_SCALE + self.scale = DEFAULT_SCALE def defprim(self, name, args, fcn, rprim=False): """ Define the primitives associated with the blocks """ @@ -1074,9 +1073,8 @@ class LogoCode: def reskin(self, media): """ Reskin the turtle with an image from a file """ - w = int(self.scale) - h = int(self.scale) - pixbuf = self.show_picture(media, 0, 0, w, h, False) + scale = int(ICON_SIZE * float(self.scale) / DEFAULT_SCALE) + pixbuf = self.show_picture(media, 0, 0, scale, scale, False) if pixbuf is not None: self.tw.active_turtle.set_shapes([pixbuf]) -- cgit v0.9.1