Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-03-25 19:56:02 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-03-25 19:56:02 (GMT)
commitacf9ac4cef907400997dfc67e6c744621897935e (patch)
treed9f0eb1d7d0e80f871d27dfc86130b3406e74b9c
parent09e4c0cd52771906bf56055286c0c7e3d75449cf (diff)
added fill blocks
-rw-r--r--tacanvas.py40
-rw-r--r--taconstants.py15
-rw-r--r--talogo.py2
3 files changed, 53 insertions, 4 deletions
diff --git a/tacanvas.py b/tacanvas.py
index 473a136..dc325d3 100644
--- a/tacanvas.py
+++ b/tacanvas.py
@@ -96,11 +96,43 @@ class TurtleGraphics:
self.pensize = 5
self.tcolor = 0
self.color = 0
+ self.fill = False
+ self.poly_points = []
self.svg = SVG()
self.svg.set_fill_color('none')
self.tw.svg_string = ''
self.clearscreen(False)
+ def start_fill(self):
+ self.fill = True
+ self.poly_points = []
+
+ def stop_fill(self):
+ self.fill = False
+ if len(self.poly_points) == 0:
+ return
+ minx = self.poly_points[0][0]
+ miny = self.poly_points[0][1]
+ maxx = minx
+ maxy = miny
+ for p in self.poly_points:
+ if p[0] < minx:
+ minx = p[0]
+ elif p[0] > maxx:
+ maxx = p[0]
+ if p[1] < miny:
+ miny = p[1]
+ elif p[1] > maxy:
+ maxy = p[1]
+ 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.poly_points = []
+
def clearscreen(self, share=True):
rect = gtk.gdk.Rectangle(0, 0, self.width, self.height)
self.gc.set_foreground(self.bgcolor)
@@ -123,6 +155,8 @@ class TurtleGraphics:
self.set_turtle(DEFAULT_TURTLE)
self.tw.svg_string = ''
self.svg.reset_min_max()
+ self.fill = False
+ self.poly_points = []
def forward(self, n, share=True):
nn = n*self.tw.coord_scale
@@ -326,6 +360,8 @@ class TurtleGraphics:
self.setshade(olds, False)
self.tw.svg_string = ''
self.svg.reset_min_max()
+ self.fill = False
+ self.poly_points = []
def set_fgcolor(self):
sh = (wrap100(self.shade) - 50)/50.0
@@ -402,6 +438,10 @@ class TurtleGraphics:
miny, maxy = y2, y1
w, h = maxx-minx, maxy-miny
self.canvas.images[0].draw_line(self.gc, x1, y1, x2, y2)
+ if self.fill and self.poly_points == []:
+ 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,
diff --git a/taconstants.py b/taconstants.py
index 65c347a..5fe6f5d 100644
--- a/taconstants.py
+++ b/taconstants.py
@@ -120,8 +120,8 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right',
'arc', 'scale', 'leftpos', 'toppos', 'rightpos',
'bottompos'],
['penup','pendown', 'setpensize', 'fillscreen', 'pensize',
- 'settextsize', 'setcolor', 'setshade', 'textsize', 'color',
- 'shade'],
+ 'setcolor', 'setshade', 'startfill', 'color', 'shade',
+ 'stopfill'],
[ 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple'],
['plus2', 'minus2', 'product2',
'division2', 'identity2', 'remainder2', 'sqrt', 'random',
@@ -178,7 +178,8 @@ BASIC_STYLE_HEAD_1ARG = ['hat']
BASIC_STYLE_TAIL = ['stopstack', 'empty']
BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace',
'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput',
- 'fullscreen', 'sandwichcollapsed', 'cartesian', 'polar']
+ 'fullscreen', 'sandwichcollapsed', 'cartesian', 'polar', 'startfill',
+ 'stopfill']
BASIC_STYLE_EXTENDED = ['picturelist', 'picture1x1', 'picture2x2',
'picture2x1', 'picture1x2', 'picture1x1a']
BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', 'image',
@@ -363,6 +364,8 @@ BLOCK_NAMES = {
'stack1':[_('action 1')],
'stack2':[_('action 2')],
'start':[_('start')],
+ 'startfill':[_('start fill')],
+ 'stopfill':[_('stop fill')],
'stopstack':[_('stop action')],
'storein':[_('store in'), _('box'), _('value')],
'storeinbox1':[_('store in box 1')],
@@ -496,6 +499,8 @@ PRIMITIVES = {
'stack1':'stack1',
'stack2':'stack2',
'start':'start',
+ 'startfill':'startfill',
+ 'stopfill':'stopfill',
'stopstack':'stopstack',
'storein':'storeinbox',
'storeinbox1':'storeinbox1',
@@ -596,7 +601,7 @@ STRING_OR_NUMBER_ARGS = ['plus2', 'equal2', 'less2', 'greater2', 'box',
'print', 'stack', 'hat', 'addturtle', 'myfunc',
'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'comment',
'sandwichtop', 'sandwichtop2', 'userdefined',
- 'userdefined2args','userdefined3args']
+ 'userdefined2args', 'userdefined3args', 'storein']
CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1',
'storeinbox2']
@@ -796,6 +801,8 @@ HELP_STRINGS = {
'stack2':_("invokes Action 2 stack"),
'stack':_("invokes named action stack"),
'start':_("connects action to toolbar run buttons"),
+ 'startfill':_("starts filled polygon (used with end fill block)"),
+ 'stopfill':_("completes filled polygon (used with start fill block)"),
'stopiton':_("Stop turtle"),
'stopstack':_("stops current action"),
'storeinbox1':_("stores numeric value in Variable 1"),
diff --git a/talogo.py b/talogo.py
index 5858735..a060b5a 100644
--- a/talogo.py
+++ b/talogo.py
@@ -339,6 +339,8 @@ class LogoCode:
'stack':[1, self.prim_stack, True],
'stack2':[0, self.prim_stack2, True],
'start':[0, lambda self: self.prim_start()],
+ 'startfill':[0, lambda self: self.tw.canvas.start_fill()],
+ 'stopfill':[0, lambda self: self.tw.canvas.stop_fill()],
'stopstack':[0, lambda self: self.prim_stopstack()],
'storeinbox1':[1, lambda self, x: self.prim_setbox('box1', None ,x)],
'storeinbox2':[1, lambda self, x: self.prim_setbox('box2', None, x)],