Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tacanvas.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-07-29 20:13:39 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-07-29 20:13:39 (GMT)
commit7fc18dcb2649dc19ddfe01fdb87fa9d6d06ad68a (patch)
treeaf91791f4616e8118691eda0d4b9be1f8ab0dad7 /tacanvas.py
parentbee1f6f2c0813756e50cce2ce1778bd298df6e72 (diff)
fixed bug in non-interactive mode
Diffstat (limited to 'tacanvas.py')
-rw-r--r--tacanvas.py308
1 files changed, 182 insertions, 126 deletions
diff --git a/tacanvas.py b/tacanvas.py
index d7a9e9a..03f69fc 100644
--- a/tacanvas.py
+++ b/tacanvas.py
@@ -21,67 +21,76 @@
import gtk
from math import sin, cos, pi
+import pango
+import cairo
+
from sprites import Sprite
from tasprite_factory import SVG
from tautils import image_to_base64, data_to_string, round_int
-import pango
-import cairo
from taconstants import CANVAS_LAYER, DEFAULT_TURTLE, BLACK, WHITE
+
import logging
_logger = logging.getLogger('turtleart-activity')
+
def wrap100(n):
+ """ A variant on mod... 101 -> 99; 199 -> 1 """
n = int(n)
n %= 200
if n > 99:
- n = 199-n
+ n = 199 - n
return n
+
def calc_shade(c, s):
+ """ Convert a color to the current shade (lightness/darkness). """
if s < 0:
- return int(c*(1+s*.8))
- return int(c+(65536-c)*s*.9)
+ return int(c * (1 + s * 0.8))
+ return int(c + (65536 - c) * s * 0.9)
+
def calc_gray(c, g):
+ """ Gray is a psuedo saturation calculation. """
if g == 100:
return c
- return int(((c*g)+(32768*(100-g)))/100)
+ return int(((c * g) + (32768 * (100 - g))) / 100)
colors = {}
-DEGTOR = 2*pi/360
+DEGTOR = 2 * pi / 360
color_table = (
- 0xFF0000,0xFF0D00,0xFF1A00,0xFF2600,0xFF3300,
- 0xFF4000,0xFF4D00,0xFF5900,0xFF6600,0xFF7300,
- 0xFF8000,0xFF8C00,0xFF9900,0xFFA600,0xFFB300,
- 0xFFBF00,0xFFCC00,0xFFD900,0xFFE600,0xFFF200,
- 0xFFFF00,0xE6FF00,0xCCFF00,0xB3FF00,0x99FF00,
- 0x80FF00,0x66FF00,0x4DFF00,0x33FF00,0x1AFF00,
- 0x00FF00,0x00FF0D,0x00FF1A,0x00FF26,0x00FF33,
- 0x00FF40,0x00FF4D,0x00FF59,0x00FF66,0x00FF73,
- 0x00FF80,0x00FF8C,0x00FF99,0x00FFA6,0x00FFB3,
- 0x00FFBF,0x00FFCC,0x00FFD9,0x00FFE6,0x00FFF2,
- 0x00FFFF,0x00F2FF,0x00E6FF,0x00D9FF,0x00CCFF,
- 0x00BFFF,0x00B3FF,0x00A6FF,0x0099FF,0x008CFF,
- 0x0080FF,0x0073FF,0x0066FF,0x0059FF,0x004DFF,
- 0x0040FF,0x0033FF,0x0026FF,0x001AFF,0x000DFF,
- 0x0000FF,0x0D00FF,0x1A00FF,0x2600FF,0x3300FF,
- 0x4000FF,0x4D00FF,0x5900FF,0x6600FF,0x7300FF,
- 0x8000FF,0x8C00FF,0x9900FF,0xA600FF,0xB300FF,
- 0xBF00FF,0xCC00FF,0xD900FF,0xE600FF,0xF200FF,
- 0xFF00FF,0xFF00E6,0xFF00CC,0xFF00B3,0xFF0099,
- 0xFF0080,0xFF0066,0xFF004D,0xFF0033,0xFF001A)
-
-#
-# A class for the Turtle graphics canvas
-#
+ 0xFF0000, 0xFF0D00, 0xFF1A00, 0xFF2600, 0xFF3300,
+ 0xFF4000, 0xFF4D00, 0xFF5900, 0xFF6600, 0xFF7300,
+ 0xFF8000, 0xFF8C00, 0xFF9900, 0xFFA600, 0xFFB300,
+ 0xFFBF00, 0xFFCC00, 0xFFD900, 0xFFE600, 0xFFF200,
+ 0xFFFF00, 0xE6FF00, 0xCCFF00, 0xB3FF00, 0x99FF00,
+ 0x80FF00, 0x66FF00, 0x4DFF00, 0x33FF00, 0x1AFF00,
+ 0x00FF00, 0x00FF0D, 0x00FF1A, 0x00FF26, 0x00FF33,
+ 0x00FF40, 0x00FF4D, 0x00FF59, 0x00FF66, 0x00FF73,
+ 0x00FF80, 0x00FF8C, 0x00FF99, 0x00FFA6, 0x00FFB3,
+ 0x00FFBF, 0x00FFCC, 0x00FFD9, 0x00FFE6, 0x00FFF2,
+ 0x00FFFF, 0x00F2FF, 0x00E6FF, 0x00D9FF, 0x00CCFF,
+ 0x00BFFF, 0x00B3FF, 0x00A6FF, 0x0099FF, 0x008CFF,
+ 0x0080FF, 0x0073FF, 0x0066FF, 0x0059FF, 0x004DFF,
+ 0x0040FF, 0x0033FF, 0x0026FF, 0x001AFF, 0x000DFF,
+ 0x0000FF, 0x0D00FF, 0x1A00FF, 0x2600FF, 0x3300FF,
+ 0x4000FF, 0x4D00FF, 0x5900FF, 0x6600FF, 0x7300FF,
+ 0x8000FF, 0x8C00FF, 0x9900FF, 0xA600FF, 0xB300FF,
+ 0xBF00FF, 0xCC00FF, 0xD900FF, 0xE600FF, 0xF200FF,
+ 0xFF00FF, 0xFF00E6, 0xFF00CC, 0xFF00B3, 0xFF0099,
+ 0xFF0080, 0xFF0066, 0xFF004D, 0xFF0033, 0xFF001A)
+
+
class TurtleGraphics:
+ """ A class for the Turtle graphics canvas """
+
def __init__(self, tw, width, height):
+ """ Create a sprite to hold the canvas. """
self.tw = tw
self.width = width
self.height = height
if self.tw.interactive_mode:
- self.canvas = Sprite(tw.sprite_list, 0, 0,
+ self.canvas = Sprite(tw.sprite_list, 0, 0,
gtk.gdk.Pixmap(self.tw.area, self.width, self.height, -1))
else:
self.canvas = Sprite(None, 0, 0, self.tw.window)
@@ -114,10 +123,12 @@ class TurtleGraphics:
self.clearscreen(False)
def start_fill(self):
+ """ Start accumulating points of a polygon to fill. """
self.fill = True
self.poly_points = []
def stop_fill(self):
+ """ Fill the polygon. """
self.fill = False
if len(self.poly_points) == 0:
return
@@ -134,16 +145,17 @@ class TurtleGraphics:
miny = p[1]
elif p[1] > maxy:
maxy = p[1]
- w = maxx-minx
- h = maxy-miny
+ w = maxx - minx
+ h = maxy - miny
self.canvas.images[0].draw_polygon(self.gc, True, self.poly_points)
- self.invalt(minx - self.pensize*self.tw.coord_scale/2 - 3,
- miny - self.pensize*self.tw.coord_scale/2 - 3,
- w + self.pensize*self.tw.coord_scale + 6,
- h + self.pensize*self.tw.coord_scale + 6)
+ self.invalt(minx - self.pensize * self.tw.coord_scale / 2 - 3,
+ miny - self.pensize * self.tw.coord_scale / 2 - 3,
+ w + self.pensize * self.tw.coord_scale + 6,
+ h + self.pensize * self.tw.coord_scale + 6)
self.poly_points = []
def clearscreen(self, share=True):
+ """Clear the canvas and reset most graphics attributes to defaults."""
rect = gtk.gdk.Rectangle(0, 0, self.width, self.height)
self.gc.set_foreground(self.bgcolor)
self.canvas.images[0].draw_rectangle(self.gc, True, *rect)
@@ -170,32 +182,38 @@ class TurtleGraphics:
self.poly_points = []
def forward(self, n, share=True):
- nn = n*self.tw.coord_scale
+ """ Move the turtle forward."""
+ nn = n * self.tw.coord_scale
self.gc.set_foreground(self.fgcolor)
oldx, oldy = self.xcor, self.ycor
try:
- self.xcor += nn*sin(self.heading*DEGTOR)
- self.ycor += nn*cos(self.heading*DEGTOR)
- except:
- pass
+ self.xcor += nn * sin(self.heading * DEGTOR)
+ self.ycor += nn * cos(self.heading * DEGTOR)
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
if self.pendown:
self.draw_line(oldx, oldy, self.xcor, self.ycor)
self.move_turtle()
if self.tw.saving_svg and self.pendown:
- self.tw.svg_string += self.svg.new_path(oldx, self.height/2-oldy)
+ self.tw.svg_string += self.svg.new_path(oldx,
+ self.height / 2 - oldy)
self.tw.svg_string += self.svg.line_to(self.xcor,
- self.height/2-self.ycor)
+ self.height / 2 - self.ycor)
self.tw.svg_string += "\"\n"
self.tw.svg_string += self.svg.style()
if self.tw.sharing() and share:
self.tw.activity.send_event("f|%s" % \
- (data_to_string([self.tw.nick, int(n)])))
+ (data_to_string([self.tw.nick,
+ int(n)])))
def seth(self, n, share=True):
+ """ Set the turtle heading. """
try:
self.heading = n
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.heading %= 360
self.turn_turtle()
if self.tw.sharing() and share:
@@ -203,10 +221,12 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(self.heading)])))
def right(self, n, share=True):
+ """ Rotate turtle clockwise """
try:
self.heading += n
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.heading %= 360
self.turn_turtle()
if self.tw.sharing() and share:
@@ -214,22 +234,24 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(self.heading)])))
def arc(self, a, r, share=True):
+ """ Draw an arc """
self.gc.set_foreground(self.fgcolor)
- rr = r*self.tw.coord_scale
+ rr = r * self.tw.coord_scale
try:
if a < 0:
self.larc(-a, rr)
else:
self.rarc(a, rr)
- except:
- pass
- # _logger.debug("moving to %f %f" % (self.xcor, self.ycor))
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.move_turtle()
if self.tw.sharing() and share:
self.tw.activity.send_event("a|%s" % \
(data_to_string([self.tw.nick, [round_int(a), round_int(r)]])))
def rarc(self, a, r):
+ """ draw a clockwise arc """
if r < 0:
r = -r
a = -a
@@ -237,31 +259,33 @@ class TurtleGraphics:
else:
s = 1
oldx, oldy = self.xcor, self.ycor
- cx = self.xcor + r*cos(self.heading*DEGTOR)
- cy = self.ycor - r*sin(self.heading*DEGTOR)
- x = self.width/2 + int(cx-r)
- y = self.height/2 - int(cy+r)
- w = int(2*r)
+ cx = self.xcor + r * cos(self.heading * DEGTOR)
+ cy = self.ycor - r * sin(self.heading * DEGTOR)
+ x = self.width / 2 + int(cx - r)
+ y = self.height / 2 - int(cy + r)
+ w = int(2 * r)
h = w
if self.pendown:
self.canvas.images[0].draw_arc(self.gc, False, x, y, w, h,
- int(180 - self.heading - a)*64, int(a)*64)
- self.invalt(x - self.pensize*self.tw.coord_scale/2 - 3,
- y - self.pensize*self.tw.coord_scale/2 - 3,
- w + self.pensize*self.tw.coord_scale + 6,
- h + self.pensize*self.tw.coord_scale + 6)
+ int(180 - self.heading - a) * 64, int(a) * 64)
+ self.invalt(x - self.pensize * self.tw.coord_scale / 2 - 3,
+ y - self.pensize * self.tw.coord_scale / 2 - 3,
+ w + self.pensize * self.tw.coord_scale + 6,
+ h + self.pensize * self.tw.coord_scale + 6)
self.right(a, False)
- self.xcor = cx - r*cos(self.heading*DEGTOR)
- self.ycor = cy + r*sin(self.heading*DEGTOR)
+ self.xcor = cx - r * cos(self.heading * DEGTOR)
+ self.ycor = cy + r * sin(self.heading * DEGTOR)
if self.tw.saving_svg and self.pendown:
- self.tw.svg_string += self.svg.new_path(oldx, self.height/2-oldy)
+ self.tw.svg_string += self.svg.new_path(oldx,
+ self.height / 2 - oldy)
self.tw.svg_string += self.svg.arc_to(self.xcor,
- self.height/2-self.ycor, r, a,
- 0, s)
+ self.height / 2 - self.ycor,
+ r, a, 0, s)
self.tw.svg_string += "\"\n"
self.tw.svg_string += self.svg.style()
def larc(self, a, r):
+ """ draw a counter-clockwise arc """
if r < 0:
r = -r
a = -a
@@ -269,49 +293,54 @@ class TurtleGraphics:
else:
s = 0
oldx, oldy = self.xcor, self.ycor
- cx = self.xcor - r*cos(self.heading*DEGTOR)
- cy = self.ycor + r*sin(self.heading*DEGTOR)
- x = self.width/2 + int(cx-r)
- y = self.height/2 - int(cy+r)
- w = int(2*r)
+ cx = self.xcor - r * cos(self.heading * DEGTOR)
+ cy = self.ycor + r * sin(self.heading * DEGTOR)
+ x = self.width / 2 + int(cx-r)
+ y = self.height / 2 - int(cy+r)
+ w = int(2 * r)
h = w
if self.pendown:
self.canvas.images[0].draw_arc(self.gc, False, x, y, w, h,
- int(360-self.heading)*64, int(a)*64)
- self.invalt(x - self.pensize*self.tw.coord_scale/2 - 3,
- y - self.pensize*self.tw.coord_scale/2 - 3,
- w + self.pensize*self.tw.coord_scale + 6,
- h + self.pensize*self.tw.coord_scale + 6)
+ int(360 - self.heading) * 64,
+ int(a) * 64)
+ self.invalt(x - self.pensize * self.tw.coord_scale / 2 - 3,
+ y - self.pensize * self.tw.coord_scale / 2 - 3,
+ w + self.pensize * self.tw.coord_scale + 6,
+ h + self.pensize * self.tw.coord_scale + 6)
self.right(-a, False)
- self.xcor = cx + r*cos(self.heading*DEGTOR)
- self.ycor = cy - r*sin(self.heading*DEGTOR)
+ self.xcor = cx + r * cos(self.heading * DEGTOR)
+ self.ycor = cy - r * sin(self.heading * DEGTOR)
if self.tw.saving_svg and self.pendown:
- self.tw.svg_string += self.svg.new_path(oldx, self.height/2-oldy)
+ self.tw.svg_string += self.svg.new_path(oldx, self.height / 2-oldy)
self.tw.svg_string += self.svg.arc_to(self.xcor,
- self.height/2-self.ycor, r, a,
- 0, s)
+ self.height / 2-self.ycor,
+ r, a, 0, s)
self.tw.svg_string += "\"\n"
self.tw.svg_string += self.svg.style()
def setxy(self, x, y, share=True):
+ """ Move turtle to position x,y """
x *= self.tw.coord_scale
y *= self.tw.coord_scale
try:
self.xcor, self.ycor = x, y
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.move_turtle()
if self.tw.sharing() and share:
self.tw.activity.send_event("x|%s" % \
(data_to_string([self.tw.nick, [round_int(x), round_int(y)]])))
def setpensize(self, ps, share=True):
+ """ Set the pen size """
try:
if ps < 0:
ps = 0
self.pensize = ps
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.tw.active_turtle.set_pen_size(ps)
self.gc.set_line_attributes(int(self.pensize*self.tw.coord_scale),
gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_MITER)
@@ -321,11 +350,13 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(ps)])))
def setcolor(self, c, share=True):
+ """ Set the pen color """
try:
self.color = c
self.tcolor = c
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.tw.active_turtle.set_color(c)
self.set_fgcolor()
self.set_textcolor()
@@ -334,10 +365,12 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(c)])))
def setgray(self, g, share=True):
+ """ Set the gray level """
try:
self.gray = g
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
if self.gray < 0:
self.gray = 0
if self.gray > 100:
@@ -350,23 +383,28 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(self.gray)])))
def settextcolor(self, c):
+ """ Set the text color """
try:
self.tcolor = c
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.set_textcolor()
def settextsize(self, c):
+ """ Set the text size """
try:
self.tw.textsize = c
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
def setshade(self, s, share=True):
+ """ Set the color shade """
try:
self.shade = s
- except:
- pass
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
self.tw.active_turtle.set_shade(s)
self.set_fgcolor()
self.set_textcolor()
@@ -375,6 +413,7 @@ class TurtleGraphics:
(data_to_string([self.tw.nick, round_int(s)])))
def fillscreen(self, c, s):
+ """ Fill screen with color/shade and reset to defaults """
oldc, olds = self.color, self.shade
self.setcolor(c, False)
self.setshade(s, False)
@@ -391,6 +430,7 @@ class TurtleGraphics:
self.poly_points = []
def set_fgcolor(self):
+ """ Set the foreground color """
if self.color == WHITE or self.shade == WHITE:
r = 0xFF00
g = 0xFF00
@@ -400,37 +440,40 @@ class TurtleGraphics:
g = 0x0000
b = 0x0000
else:
- sh = (wrap100(self.shade) - 50)/50.0
+ sh = (wrap100(self.shade) - 50) / 50.0
rgb = color_table[wrap100(self.color)]
- r = (rgb>>8)&0xff00
+ r = (rgb >> 8) & 0xff00
r = calc_gray(r, self.gray)
r = calc_shade(r, sh)
- g = rgb&0xff00
+ g = rgb & 0xff00
g = calc_gray(g, self.gray)
g = calc_shade(g, sh)
- b = (rgb<<8)&0xff00
+ b = (rgb << 8) & 0xff00
b = calc_gray(b, self.gray)
b = calc_shade(b, sh)
- self.fgrgb = [r>>8, g>>8, b>>8]
+ self.fgrgb = [r >> 8, g >> 8, b >> 8]
self.fgcolor = self.cm.alloc_color(r, g, b)
self.svg.set_stroke_color("#%02x%02x%02x" % (self.fgrgb[0],
self.fgrgb[1],
self.fgrgb[2]))
def set_textcolor(self):
- sh = (wrap100(self.shade) - 50)/50.0
+ """ Set the text color """
+ sh = (wrap100(self.shade) - 50) / 50.0
rgb = color_table[wrap100(self.tcolor)]
- r, g, b = (rgb>>8)&0xff00, rgb&0xff00, (rgb<<8)&0xff00
+ r, g, b = (rgb >> 8) & 0xff00, rgb & 0xff00, (rgb << 8) & 0xff00
r, g, b = calc_shade(r, sh), calc_shade(g, sh), calc_shade(b, sh)
self.tw.textcolor = self.cm.alloc_color(r, g, b)
def setpen(self, bool, share=True):
+ """ Lower or raise the pen """
self.pendown = bool
if self.tw.sharing() and share:
self.tw.activity.send_event("p|%s" % \
(data_to_string([self.tw.nick, bool])))
def draw_pixbuf(self, pixbuf, a, b, x, y, w, h, path):
+ """ Draw a pixbuf """
w *= self.tw.coord_scale
h *= self.tw.coord_scale
self.canvas.images[0].draw_pixbuf(self.gc, pixbuf, a, b, x, y)
@@ -438,23 +481,28 @@ class TurtleGraphics:
if self.tw.saving_svg:
if self.tw.running_sugar:
# In Sugar, we need to embed the images inside the SVG
- self.tw.svg_string += self.svg.image(x-self.width/2, y, w, h,
- path, image_to_base64(pixbuf, self.tw.activity))
+ self.tw.svg_string += self.svg.image(x - self.width / 2,
+ y, w, h, path,
+ image_to_base64(pixbuf,
+ self.tw.activity))
else:
- self.tw.svg_string += self.svg.image(x-self.width/2, y, w, h,
- path)
+ self.tw.svg_string += self.svg.image(x - self.width / 2,
+ y, w, h, path)
def draw_text(self, label, x, y, size, w):
+ """ Draw text """
w *= self.tw.coord_scale
self.gc.set_foreground(self.tw.textcolor)
fd = pango.FontDescription('Sans')
try:
- fd.set_size(int(size*self.tw.coord_scale)*pango.SCALE)
- except:
- pass
+ fd.set_size(int(size * self.tw.coord_scale) * pango.SCALE)
+ except TypeError, ValueError:
+ _logger.debug("bad value sent to %s" % (__name__))
+ return
if self.tw.interactive_mode:
if type(label) == str or type(label) == unicode:
- pl = self.tw.window.create_pango_layout(label.replace("\0"," "))
+ pl = self.tw.window.create_pango_layout(label.replace("\0",
+ " "))
elif type(label) == float or type(label) == int:
pl = self.tw.window.create_pango_layout(str(label))
else:
@@ -470,17 +518,18 @@ class TurtleGraphics:
context.set_font_size(size)
q, k, w, h = context.text_extents(message)[:4]
context.set_source_rgb(0, 0, 0)
- context.move_to(x, y+h)
+ context.move_to(x, y + h)
context.show_text(message)
if self.tw.saving_svg and self.pendown:
- self.tw.svg_string += self.svg.text(x - self.width/2,
+ self.tw.svg_string += self.svg.text(x - self.width / 2,
y + size,
size, w, label)
def draw_line(self, x1, y1, x2, y2):
- x1, y1 = self.width/2 + int(x1), self.height/2 - int(y1)
- x2, y2 = self.width/2 + int(x2), self.height/2 - int(y2)
+ """ Draw a line """
+ x1, y1 = self.width / 2 + int(x1), self.height / 2 - int(y1)
+ x2, y2 = self.width / 2 + int(x2), self.height / 2 - int(y2)
if x1 < x2:
minx, maxx = x1, x2
else:
@@ -495,24 +544,30 @@ class TurtleGraphics:
self.poly_points.append((x1, y1))
if self.fill:
self.poly_points.append((x2, y2))
- self.invalt(minx - self.pensize*self.tw.coord_scale/2 - 3,
- miny - self.pensize*self.tw.coord_scale/2 - 3,
- w + self.pensize*self.tw.coord_scale + 6,
- h + self.pensize*self.tw.coord_scale + 6)
+ self.invalt(minx - self.pensize * self.tw.coord_scale / 2 - 3,
+ miny - self.pensize * self.tw.coord_scale / 2 - 3,
+ w + self.pensize * self.tw.coord_scale + 6,
+ h + self.pensize * self.tw.coord_scale + 6)
def turn_turtle(self):
+ """ Change the orientation of the turtle """
self.tw.active_turtle.set_heading(self.heading)
def move_turtle(self):
- x, y = self.width/2 + int(self.xcor), self.height/2 - int(self.ycor)
+ """ 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))
def invalt(self, x, y, w, h):
+ """ Mark a region for refresh """
if self.tw.interactive_mode:
- self.tw.area.invalidate_rect(gtk.gdk.Rectangle(int(x+self.cx),
- int(y+self.cy), int(w), int(h)), False)
+ self.tw.area.invalidate_rect(gtk.gdk.Rectangle(int(x + self.cx),
+ int(y + self.cy),
+ int(w), int(h)),
+ False)
def set_turtle(self, k, colors=None):
+ """ Select the current turtle and associated pen status """
if not self.tw.turtles.dict.has_key(k):
# 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)
@@ -521,8 +576,8 @@ class TurtleGraphics:
self.tw.active_turtle.set_pen_state(True)
self.tw.active_turtle = self.tw.turtles.get_turtle(k, False)
tx, ty = self.tw.active_turtle.get_xy()
- self.xcor = -self.width/2 + tx + 28
- self.ycor = self.height/2 - ty - 30
+ self.xcor = -self.width / 2 + tx + 28
+ self.ycor = self.height / 2 - ty - 30
self.heading = self.tw.active_turtle.get_heading()
self.setcolor(self.tw.active_turtle.get_color(), False)
self.setgray(self.tw.active_turtle.get_gray(), False)
@@ -531,6 +586,7 @@ class TurtleGraphics:
self.setpen(self.tw.active_turtle.get_pen_state(), False)
def svg_close(self):
+ """ Close current SVG graphic """
if self.tw.svg_string == '':
return
self.svg.calc_w_h(False)