diff options
author | Walter Bender <walter@walter-laptop.(none)> | 2010-02-23 00:34:17 (GMT) |
---|---|---|
committer | Walter Bender <walter@walter-laptop.(none)> | 2010-02-23 00:34:17 (GMT) |
commit | b6f4cb03eb6c771c5eb0492aba3782a9ea922130 (patch) | |
tree | 7fbc7a99267dd0c73924f3b844e40f9613e19787 | |
parent | 81f708694c8a9ca8fe25ed5fff4dccba64d48007 (diff) |
more turtle svg cleanups
-rw-r--r-- | tablock.py | 17 | ||||
-rw-r--r-- | taconstants.py | 3 | ||||
-rw-r--r-- | talogo.py | 15 | ||||
-rwxr-xr-x | tasprite_factory.py | 86 | ||||
-rw-r--r-- | taturtle.py | 9 |
5 files changed, 109 insertions, 21 deletions
@@ -329,6 +329,8 @@ class Block: self._make_flow_style_1arg(svg) elif self.name in FLOW_STYLE_BOOLEAN: self._make_flow_style_boolean(svg) + elif self.name in FLOW_STYLE_WHILE: + self._make_flow_style_while(svg) elif self.name in FLOW_STYLE_ELSE: self._make_flow_style_else(svg) elif self.name in COLLAPSIBLE_TOP: @@ -627,6 +629,21 @@ class Block: ['flow', False, self.svg.docks[3][0], self.svg.docks[3][1], ']']] + def _make_flow_style_while(self, svg): + self.svg.expand(self.dx+self.ex, self.ey) + self.svg.set_slot(True) + self.svg.set_tab(True) + self.svg.set_boolean(True) + self._make_basic_flow(svg) + self.docks = [['flow', True, self.svg.docks[0][0], + self.svg.docks[0][1]], + ['bool', False, self.svg.docks[1][0], + self.svg.docks[1][1], '['], + ['flow', False, self.svg.docks[2][0], + self.svg.docks[2][1], ']['], + ['flow', False, self.svg.docks[3][0], + self.svg.docks[3][1], ']']] + def _make_flow_style_else(self, svg): self.svg.expand(self.dx+self.ex, self.ey) self.svg.set_slot(True) diff --git a/taconstants.py b/taconstants.py index 0eea6aa..9c559f5 100644 --- a/taconstants.py +++ b/taconstants.py @@ -189,6 +189,7 @@ FLOW_STYLE = ['forever'] FLOW_STYLE_TAIL = ['hspace'] FLOW_STYLE_1ARG = ['repeat'] FLOW_STYLE_BOOLEAN = ['if', 'while', 'until'] +FLOW_STYLE_WHILE = ['while2'] FLOW_STYLE_ELSE = ['ifelse'] COLLAPSIBLE_TOP = ['sandwichtop'] COLLAPSIBLE_BOTTOM = ['sandwichbottom'] @@ -353,6 +354,7 @@ BLOCK_NAMES = { 'vspace':[' '], 'wait':[_('wait')], 'while':[_('while')], + 'while2':[_('while')], 'width':[_('width')], 'write':[_('write')], 'xcor':[_('xcor')], @@ -470,6 +472,7 @@ PRIMITIVES = { 'topy':'topy', 'vspace':'nop', 'wait':'wait', + 'while2':'while', 'width':'hres', 'write':'write', 'xcor':'xcor', @@ -378,6 +378,7 @@ class LogoCode: 'video':[1, lambda self,x: self.play_movie(x)], 'vres':[0, lambda self: self.tw.canvas.height/self.tw.coord_scale], 'wait':[1, self.prim_wait, True], + # 'while':[2, self.prim_while, True], 'write':[2, lambda self, x,y: self.write(self, x,y)], 'xcor':[0, lambda self: self.tw.canvas.xcor/self.tw.coord_scale], 'ycor':[0, lambda self: self.tw.canvas.ycor/self.tw.coord_scale], @@ -686,7 +687,7 @@ class LogoCode: self.arglist.append(self.iresult) if self.cfun.rprim: if type(self.cfun.fcn) == self.listtype: - # print "evalsym rprim list: ", token + print "evalsym rprim list: ", token self.icall(self.ufuncall, self.cfun.fcn) yield True else: @@ -832,6 +833,18 @@ class LogoCode: self.ireturn() yield True + ''' + def prim_while(self, list1, list2): + list = [self.intern('if')] + for i in list1: + list.append(i) + list.append(list2) + while self.icall(self.evline, list[:]): + yield True + self.ireturn() + yield True + ''' + def prim_if(self, bool, list): if bool: self.icall(self.evline, list[:]) diff --git a/tasprite_factory.py b/tasprite_factory.py index ccfd567..bdd7202 100755 --- a/tasprite_factory.py +++ b/tasprite_factory.py @@ -304,19 +304,79 @@ class SVG: def turtle(self, colors): self._fill, self._stroke = colors[0], colors[1] - svg = " <path d=\"M 27.497 48.279 C 26.944 48.279 26.398 48.244 25.86 48.179 L 27.248 50.528 L 28.616 48.215 C 28.245 48.245 27.875 48.279 27.497 48.279 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 40.16 11.726 C 37.996 11.726 36.202 13.281 35.817 15.333 C 37.676 16.678 39.274 18.448 40.492 20.541 C 42.777 20.369 44.586 18.48 44.586 16.151 C 44.586 13.707 42.604 11.726 40.16 11.726 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 40.713 39.887 C 39.489 42.119 37.853 44.018 35.916 45.443 C 36.437 47.307 38.129 48.682 40.16 48.682 C 42.603 48.682 44.586 46.702 44.586 44.258 C 44.586 42.003 42.893 40.162 40.713 39.887 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 14.273 39.871 C 12.02 40.077 10.249 41.95 10.249 44.258 C 10.249 46.701 12.229 48.682 14.673 48.682 C 16.737 48.682 18.457 47.262 18.945 45.35 C 17.062 43.934 15.47 42.061 14.273 39.871 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 19.026 15.437 C 18.683 13.334 16.872 11.726 14.673 11.726 C 12.229 11.726 10.249 13.707 10.249 16.15 C 10.249 18.532 12.135 20.46 14.494 20.556 C 15.68 18.513 17.226 16.772 19.026 15.437 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 27.497 12.563 C 29.405 12.563 31.225 12.974 32.915 13.691 C 33.656 12.615 34.093 11.314 34.093 9.908 C 34.093 6.221 31.104 3.231 27.416 3.231 C 23.729 3.231 20.74 6.221 20.74 9.908 C 20.74 11.336 21.192 12.657 21.956 13.742 C 23.68 12.993 25.543 12.563 27.497 12.563 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 43.102 30.421 C 43.102 35.1554 41.4568 39.7008 38.5314 43.0485 C 35.606 46.3963 31.6341 48.279 27.497 48.279 C 23.3599 48.279 19.388 46.3963 16.4626 43.0485 C 13.5372 39.7008 11.892 35.1554 11.892 30.421 C 11.892 20.6244 18.9364 12.563 27.497 12.563 C 36.0576 12.563 43.102 20.6244 43.102 30.421 Z\" stroke_width=\"3.5\" fill=\"" + self._fill + ";\" stroke=\"" + self._stroke + "\" />\n" - svg += " <path d=\"M 25.875 33.75 L 24.333 29.125 L 27.497 26.538 L 31.112 29.164 L 29.625 33.833 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" - svg += " <path d=\"M 27.501 41.551 C 23.533 41.391 21.958 39.542 21.958 39.542 L 25.528 35.379 L 29.993 35.547 L 33.125 39.667 C 33.125 39.667 30.235 41.661 27.501 41.551 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" - svg += " <path d=\"M 18.453 33.843 C 17.604 30.875 18.625 26.959 18.625 26.959 L 22.625 29.126 L 24.118 33.755 L 20.536 37.988 C 20.536 37.987 19.071 35.998 18.453 33.843 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" - svg += " <path d=\"M 19.458 25.125 C 19.458 25.125 19.958 23.167 22.497 21.303 C 24.734 19.66 26.962 19.583 26.962 19.583 L 26.925 24.564 L 23.404 27.314 L 19.458 25.125 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" - svg += " <path d=\"M 32.084 27.834 L 28.625 24.959 L 29 19.75 C 29 19.75 30.834 19.708 32.959 21.417 C 35.187 23.208 36.321 26.4 36.321 26.4 L 32.084 27.834 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" - svg += " <path d=\"M 31.292 34.042 L 32.605 29.578 L 36.792 28.042 C 36.792 28.042 37.469 30.705 36.75 33.709 C 36.21 35.965 34.666 38.07 34.666 38.07 L 31.292 34.042 Z\" stroke_width=\"3.5\" fill=\"" + self._stroke + ";\" stroke=\"none\" />\n" + svg = "%s%s%s%s%s%s%s%s" % (" <path d=\"M 27.5 48.3 ", + "C 26.9 48.3 26.4 48.2 25.9 48.2 L 27.2 50.5 L 28.6 48.2 ", + "C 28.2 48.2 27.9 48.3 27.5 48.3 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, + "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 40.2 11.7 ", + "C 38.0 11.7 36.2 13.3 35.8 15.3 ", + "C 37.7 16.7 39.3 18.4 40.5 20.5 ", + "C 42.8 20.4 44.6 18.5 44.6 16.2 ", + "C 44.6 13.7 42.6 11.7 40.2 11.7 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 40.7 39.9 ", + "C 39.5 42.1 37.9 44.0 35.9 45.4 ", + "C 36.4 47.3 38.1 48.7 40.2 48.7 ", + "C 42.6 48.7 44.6 46.7 44.6 44.3 ", + "C 44.6 42.0 42.9 40.2 40.7 39.9 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 14.3 39.9 ", + "C 12.0 40.1 10.2 42.0 10.2 44.3 ", + "C 10.2 46.7 12.2 48.7 14.7 48.7 ", + "C 16.7 48.7 18.5 47.3 18.9 45.4 ", + "C 17.1 43.9 15.5 42.1 14.3 39.9 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 19.0 15.4 ", + "C 18.7 13.3 16.9 11.7 14.7 11.7 ", + "C 12.2 11.7 10.2 13.7 10.2 16.2 ", + "C 10.2 18.5 12.1 20.5 14.5 20.6 ", + "C 15.7 18.5 17.2 16.8 19.0 15.4 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 27.5 12.6 ", + "C 29.4 12.6 31.2 13.0 32.9 13.7 ", + "C 33.7 12.6 34.1 11.3 34.1 9.9 ", + "C 34.1 6.2 31.1 3.2 27.4 3.2 ", + "C 23.7 3.2 20.7 6.2 20.7 9.9 ", + "C 20.7 11.3 21.2 12.7 22.0 13.7 ", + "C 23.7 13.0 25.5 12.6 27.5 12.6 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s%s%s%s%s%s%s%s" % (" <path d=\"M 43.1 30.4 ", + "C 43.1 35.2 41.5 39.7 38.5 43.0 ", + "C 35.6 46.4 31.6 48.3 27.5 48.3 ", + "C 23.4 48.3 19.4 46.4 16.5 43.0 ", + "C 13.5 39.7 11.9 35.2 11.9 30.4 ", + "C 11.9 20.6 18.9 12.6 27.5 12.6 ", + "C 36.1 12.6 43.1 20.6 43.1 30.4 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._fill, ";\" stroke=\"", self._stroke, "\" />\n") + svg +="%s%s%s%s%s" % (" <path d=\"M 25.9 33.8 L 24.3 29.1 ", + "L 27.5 26.5 L 31.1 29.2 L 29.6 33.8 Z\" stroke_width=\"3.5\" ", + "fill=\"", self._stroke, ";\" stroke=\"none\" />\n") + svg +="%s%s%s%s%s%s" % (" <path d=\"M 27.5 41.6 ", + "C 23.5 41.4 22.0 39.5 22.0 39.5 L 25.5 35.4 L 30.0 35.5 ", + "L 33.1 39.7 C 33.1 39.7 30.2 41.7 27.5 41.6 Z\" ", + "stroke_width=\"3.5\" fill=\"", self._stroke, + ";\" stroke=\"none\" />\n") + svg +="%s%s%s%s%s%s" % (" <path d=\"M 18.5 33.8 ", + "C 17.6 30.9 18.6 27.0 18.6 27.0 L 22.6 29.1 L 24.1 33.8 ", + "L 20.5 38.0 C 20.5 38.0 19.1 36.0 18.4 33.8 Z\" ", + "stroke_width=\"3.5\" fill=\"", self._stroke, + ";\" stroke=\"none\" />\n") + svg +="%s%s%s%s%s%s" % (" <path d=\"M 19.5 25.1 ", + "C 19.5 25.1 20.0 23.2 22.5 21.3 ", + "C 24.7 19.7 27.0 19.6 27.0 19.6 L 26.9 24.6 L 23.4 27.3 ", + "L 19.5 25.1 Z\" stroke_width=\"3.5\" fill=\"", self._stroke, + ";\" stroke=\"none\" />\n") + svg +="%s%s%s%s%s%s" % (" <path d=\"M 32.1 27.8 L 28.6 25.0 ", + "L 29 19.8 C 29 19.8 30.8 19.7 33.0 21.4 ", + "C 35.2 23.2 36.3 26.4 36.3 26.4 L 32.1 27.8 Z\" ", + "stroke_width=\"3.5\" fill=\"", self._stroke, + ";\" stroke=\"none\" />\n") + svg +="%s%s%s%s%s%s" % (" <path d=\"M 31.3 34.0 L 32.6 29.6 ", + "L 36.8 28.0 C 36.8 28.0 37.5 30.7 36.8 33.7 ", + "C 36.2 36.0 34.7 38.1 34.7 38.1 L 31.3 34.0 Z\" ", + "stroke_width=\"3.5\" fill=\"", self._stroke, + ";\" stroke=\"none\" />\n") self._width, self._height = 55, 55 svg += self._footer() return self._header() + svg diff --git a/taturtle.py b/taturtle.py index 7ed6930..9de4f58 100644 --- a/taturtle.py +++ b/taturtle.py @@ -83,7 +83,7 @@ class Turtles: def get_pixbufs(self): if self.default_pixbufs == []: self.default_pixbufs = generate_turtle_pixbufs( - ["#008000", "#00A000", "#D0D000", "#808000"]) + ["#008000", "#00A000"]) return(self.default_pixbufs) # @@ -106,12 +106,7 @@ class Turtle: if colors is None: self.shapes = turtles.get_pixbufs() else: - if len(colors) == 2: - self.colors = colors[:] - self.colors.append(colors[0]) - self.colors.append(colors[1]) - elif len(colors) == 4: - self.colors=colors[:] + self.colors = colors[:] self.shapes = generate_turtle_pixbufs(self.colors) self.spr = Sprite(turtles.sprite_list, 0, 0, self.shapes[0]) |