From b6f4cb03eb6c771c5eb0492aba3782a9ea922130 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 23 Feb 2010 00:34:17 +0000 Subject: more turtle svg cleanups --- diff --git a/tablock.py b/tablock.py index 1b79d4b..304c870 100644 --- a/tablock.py +++ b/tablock.py @@ -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', diff --git a/talogo.py b/talogo.py index da4a8b2..65f1741 100644 --- a/talogo.py +++ b/talogo.py @@ -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 = " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" - svg += " \n" + svg = "%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s" % (" \n") + svg +="%s%s%s%s%s%s" % (" \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]) -- cgit v0.9.1