diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-08-12 22:09:54 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-08-12 22:09:54 (GMT) |
commit | b3d151b60e285339a4f39708f5dce818151a8419 (patch) | |
tree | 449f0057fc4043a464eab63804866cc2c16207ae /TurtleArt | |
parent | 26355ab5b517d65d87cfcb239fca5365ec49cd49 (diff) |
read pixel block
Diffstat (limited to 'TurtleArt')
-rw-r--r-- | TurtleArt/tacanvas.py | 5 | ||||
-rw-r--r-- | TurtleArt/taconstants.py | 7 | ||||
-rw-r--r-- | TurtleArt/talogo.py | 8 |
3 files changed, 16 insertions, 4 deletions
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index 30431a7..667cc0f 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -566,10 +566,11 @@ class TurtleGraphics: int(w), int(h)), False) - def read_pixel(self, x, y): + def get_pixel(self): """ Read the pixel at x, y """ if self.tw.interactive_mode: - return self.canvas.get_pixel((x, y)) + return self.canvas.get_pixel((self.width / 2 + int(self.xcor), + self.height / 2 - int(self.ycor))) else: return(-1, -1, -1, -1) diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 2998885..5088b8f 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -135,7 +135,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', ['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap', 'myfunc1arg', 'userdefined', 'addturtle', 'comment', 'print', 'cartesian', 'width', 'height', 'polar', 'sandwichtop', - 'sandwichbottom'], + 'sandwichbottom', 'readpixel'], ['journal', 'audio', 'description', 'hideblocks', 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'picturelist', 'picture1x1a', 'picture1x1', 'picture2x2', 'picture2x1', @@ -183,7 +183,7 @@ BASIC_STYLE_TAIL = ['stopstack', 'empty'] BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace', 'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput', 'fullscreen', 'sandwichcollapsed', 'cartesian', 'polar', 'startfill', - 'stopfill'] + 'stopfill', 'readpixel'] BASIC_STYLE_EXTENDED = ['picturelist', 'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2', 'picture1x1a'] BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', 'image', @@ -337,6 +337,7 @@ BLOCK_NAMES = { 'purple':[_('purple')+' = 90'], 'push':[_('push')], 'random':[_('random'), _('min'), _('max')], + 'readpixel':[_('read pixel')], 'red':[_('red')+' = 0'], 'remainder2':[_('mod')], 'repeat':[' ',_('repeat')], @@ -479,6 +480,7 @@ PRIMITIVES = { 'push':'push', 'random':'random', 'red':'red', + 'readpixel':'readpixel', 'remainder2':'mod', 'repeat':'repeat', 'resistance':'resistance', @@ -783,6 +785,7 @@ HELP_STRINGS = { 'product2':_("multiplies two numeric inputs"), 'push':_("pushes value onto FILO (first-in last-out heap)"), 'random':_("returns random number between minimum (top) and maximum (bottom) values"), + 'readpixel':_("RGB color under the turtle is pushed to the stack"), 'remainder2':_("modular (remainder) operator"), 'repeat':_("loops specified number of times"), 'resistance':_("sensor input resistance"), diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 318bb7e..84da6d3 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -315,6 +315,7 @@ class LogoCode: 'purple':[0, lambda self: 90], 'push':[1, lambda self, x: self.prim_push(x)], 'random':[2, lambda self, x, y: tarandom(x, y)], + 'readpixel':[0, lambda self: self.read_pixel()], 'red':[0, lambda self: 0], 'repeat':[2, self.prim_repeat, True], 'right':[1, lambda self, x: self.tw.canvas.right(x)], @@ -1170,6 +1171,13 @@ class LogoCode: self.tw.canvas.draw_text(text, int(x), int(y), self.body_height, int(w)) + def read_pixel(self): + """ Read r, g, b, a from the canvas and push b, g, r to the stack """ + r, g, b, a = self.tw.canvas.get_pixel() + self.heap.append(b) + self.heap.append(g) + self.heap.append(r) + # Depreciated block methods def draw_title(self, title, x, y): |