diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-04-28 15:59:22 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-04-28 15:59:22 (GMT) |
commit | a1bc5432ade43b03b19d90e03e458bb5ffbc2932 (patch) | |
tree | 8041c24629983491f8029cad9f00895f00f0d00b | |
parent | 881a064cb0235b4676166dd4c0c175305b04baad (diff) |
clean up
-rw-r--r-- | tacanvas.py | 26 | ||||
-rw-r--r-- | taconstants.py | 172 | ||||
-rw-r--r-- | talogo.py | 2 | ||||
-rw-r--r-- | taturtle.py | 9 |
4 files changed, 123 insertions, 86 deletions
diff --git a/tacanvas.py b/tacanvas.py index dc325d3..28656aa 100644 --- a/tacanvas.py +++ b/tacanvas.py @@ -41,6 +41,11 @@ def calc_shade(c, s): return int(c*(1+s*.8)) return int(c+(65536-c)*s*.9) +def calc_gray(c, g): + if g == 100: + return c + return int(((c*g)+(32768*(100-g)))/100) + colors = {} DEGTOR = 2*pi/360 @@ -96,6 +101,7 @@ class TurtleGraphics: self.pensize = 5 self.tcolor = 0 self.color = 0 + self.gray = 100 self.fill = False self.poly_points = [] self.svg = SVG() @@ -139,6 +145,7 @@ class TurtleGraphics: self.canvas.images[0].draw_rectangle(self.gc, True, *rect) self.invalt(0, 0, self.width, self.height) self.setpensize(5, share) + self.setgray(100, share) self.setcolor(0, share) self.settextcolor(70) self.settextsize(48) @@ -322,6 +329,22 @@ class TurtleGraphics: self.tw.activity.send_event("c|%s" % \ (data_to_string([self.tw.nick, round_int(c)]))) + def setgray(self, g, share=True): + try: + self.gray = g + except: + pass + if self.gray < 0: + self.gray = 0 + if self.gray > 100: + self.gray = 100 + self.set_fgcolor() + self.set_textcolor() + self.tw.active_turtle.set_gray(self.gray) + if self.tw.sharing() and share: + self.tw.activity.send_event("g|%s" % \ + (data_to_string([self.tw.nick, round_int(self.gray)]))) + def settextcolor(self, c): try: self.tcolor = c @@ -367,6 +390,8 @@ class TurtleGraphics: sh = (wrap100(self.shade) - 50)/50.0 rgb = color_table[wrap100(self.color)] r, g, b = (rgb>>8)&0xff00, rgb&0xff00, (rgb<<8)&0xff00 + r, g, b = calc_gray(r, self.gray), calc_gray(g, self.gray),\ + calc_gray(b, self.gray) r, g, b = calc_shade(r, sh), calc_shade(g, sh), calc_shade(b, sh) self.fgrgb = [r>>8, g>>8, b>>8] self.fgcolor = self.cm.alloc_color(r, g, b) @@ -472,6 +497,7 @@ class TurtleGraphics: 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) self.setshade(self.tw.active_turtle.get_shade(), False) self.setpensize(self.tw.active_turtle.get_pen_size(), False) self.setpen(self.tw.active_turtle.get_pen_state(), False) diff --git a/taconstants.py b/taconstants.py index eabce05..3561655 100644 --- a/taconstants.py +++ b/taconstants.py @@ -246,21 +246,21 @@ PYTHON_SKIN = ['nop', 'userdefined', 'userdefined2args', 'userdefined3args'] # BLOCK_NAMES = { 'addturtle':[_('turtle')], - 'and2':[_('and')], + 'and2':[' '], 'arc':[_('arc'), _('angle'), _('radius')], 'audio':[' '], 'back':[_('back')], 'blue':[_('blue')+' = 70'], - 'bottompos':[_('bottom')], - 'bottomy':[_('picture bottom')], + 'bottompos':[' '], + 'bottomy':[' '], 'box':[_('box')], - 'box1':[_('box 1')], - 'box2':[_('box 2')], + 'box1':[' '], + 'box2':[' '], 'cartesian':[_('Cartesian')], 'clean':[_(' clean ')], - 'clearheap':[_('empty heap')], + 'clearheap':[' '], 'color':[_('color')], - 'comment':[_('comment')], + 'comment':[' '], 'cyan':[_('cyan')+' = 50'], 'decription':[' '], 'division2':['/'], @@ -269,38 +269,38 @@ BLOCK_NAMES = { 'fillscreen':[_('fill screen'), _('color'), _('shade')], 'forever':[_('forever')], 'forward':[_('forward')], - 'fullscreen':[_('full screen')], + 'fullscreen':[' '], 'greater2':[">"], 'green':[_('green')+' = 30'], 'hat':[_('action')], - 'hat1':[_('action 1')], - 'hat2':[_('action 2')], + 'hat1':[' '], + 'hat2':[' '], 'heading':[_('heading')], - 'height':[_('height')], + 'height':[' '], 'hideblocks':[_('hide blocks')], 'hspace':[' '], 'identity2':['←'], 'if':[' ', _('if'), _('then')], - 'ifelse':[' ', _('if'), _('then else')], + 'ifelse':[' ', ' ', ' '], 'image':[_('show')], 'journal':[' '], - 'kbinput':[_('query keyboard')], - 'keyboard':[_('keyboard')], - 'left':[_('left')], - 'leftpos':[_('left')], - 'leftx':[_('picture left')], + 'kbinput':[' '], + 'keyboard':[' '], + 'left':[' '], + 'leftpos':[' '], + 'leftx':[' '], 'less2':['<'], 'list':['list'], 'minus2':['–'], - 'myfunc':[_('Python'), 'f(x)', 'x'], - 'myfunc1arg':[_('Python'), 'f(x)', 'x'], - 'myfunc2arg':[_('Python'), 'f(x,y)', ' '], - 'myfunc3arg':[_('Python'), 'f(x,y,z)', ' '], - 'nop':[_(' ')], - 'not':[_('not')], + 'myfunc':[' ', 'f(x)', 'x'], + 'myfunc1arg':[' ', 'f(x)', 'x'], + 'myfunc2arg':[' ', 'f(x,y)', ' '], + 'myfunc3arg':[' ', 'f(x,y,z)', ' '], + 'nop':[' '], + 'not':[' '], 'number':['100'], 'orange':[_('orange')+' = 10'], - 'or2':[_('or')], + 'or2':[' '], 'pendown':[_('pen down')], 'pensize':[_('pen size')], 'penup':[_('pen up')], @@ -323,42 +323,42 @@ BLOCK_NAMES = { 'red':[_('red')+' = 0'], 'remainder2':[_('mod')], 'repeat':[' ',_('repeat')], - 'resistance':[_('resistance')], - 'restore':[_('restore last')], - 'restoreall':[_('restore all')], - 'right':[_('right')], - 'rightpos':[_('right')], - 'rightx':[_('picture right')], - 'savepix':[_('save picture')], - 'savesvg':[_('save SVG')], + 'resistance':[' '], + 'restore':[' '], + 'restoreall':[' '], + 'right':[' '], + 'rightpos':[' '], + 'rightx':[' '], + 'savepix':[' '], + 'savesvg':[' '], 'sandwichbottom':[' '], - 'sandwichcollapsed':[_('click to open')], - 'sandwichtop':[_('top of stack')], - 'sandwichtop2':[_('top of stack')], + 'sandwichcollapsed':[' '], + 'sandwichtop':[' '], + 'sandwichtop2':[' '], 'scale':[_('scale')], 'setcolor':[_('set color')], 'seth':[_('set heading')], 'setpensize':[_('set pen size')], 'setscale':[_('set scale')], 'setshade':[_('set shade')], - 'settextcolor':[_('set text color')], - 'settextsize':[_('set text size')], + 'settextcolor':[' '], + 'settextsize':[' '], 'setxy':[_('set xy'), _('x'), _('y')], 'shade':[_('shade')], 'show':[_('show')], - 'showblocks':[_('show blocks')], - 'showaligned':[_('show aligned')], + 'showblocks':[' '], + 'showaligned':[' '], 'sqrt':['√'], 'stack':[_('action')], - 'stack1':[_('action 1')], - 'stack2':[_('action 2')], + 'stack1':[' '], + 'stack2':[' '], 'start':[_('start')], 'startfill':[_('start fill')], 'stopfill':[_('end fill')], 'stopstack':[_('stop action')], 'storein':[_('store in'), _('box'), _('value')], - 'storeinbox1':[_('store in box 1')], - 'storeinbox2':[_('store in box 2')], + 'storeinbox1':[' '], + 'storeinbox2':[' '], 'string':[_('text')], 'template1x1':[' '], 'template1x1a':[' '], @@ -366,24 +366,24 @@ BLOCK_NAMES = { 'template2x1':[' '], 'template2x2':[' '], 'templatelist':[' '], - 'textsize':[_('text size')], - 'titlex':[_('title x')], - 'titley':[_('title y')], - 'toppos':[_('top')], - 'topy':[_('picture top')], - 'turtle':[_('turtle')], - 'until':[_('until')], - 'userdefined':[_(' ')], - 'userdefined2args':[_(' ')], - 'userdefined3args':[_(' ')], - 'voltage':[_('voltage')], - 'volume':[_('volume')], + 'textsize':[' '], + 'titlex':[' '], + 'titley':[' '], + 'toppos':[' '], + 'topy':[' '], + 'turtle':[' '], + 'until':[' '], + 'userdefined':[' '], + 'userdefined2args':[' '], + 'userdefined3args':[' '], + 'voltage':[' '], + 'volume':[' '], 'vspace':[' '], 'wait':[_('wait')], 'while':[_('while')], 'while2':[_('while')], - 'width':[_('width')], - 'write':[_('write')], + 'width':[' '], + 'write':[' '], 'xcor':[_('xcor')], 'ycor':[_('ycor')], 'yellow':[_('yellow')+' = 20']} @@ -569,12 +569,12 @@ DEFAULTS = { 'storeinbox2':[100], 'storein':[_('my box'), 100], 'string':[_('text')], - 'template1x1':[_('Title'), 'None'], - 'template1x1a':[_('Title'), 'None'], - 'template1x2':[_('Title'), 'None', 'None'], - 'template2x1':[_('Title'), 'None', 'None'], - 'template2x2':[_('Title'), 'None', 'None', 'None', 'None'], - 'templatelist':[_('Title'), '∙ '], + 'template1x1':[' ', 'None'], + 'template1x1a':[' ', 'None'], + 'template1x2':[' ', 'None', 'None'], + 'template2x1':[' ', 'None', 'None'], + 'template2x2':[' ', 'None', 'None', 'None', 'None'], + 'templatelist':[' ', '∙ '], 'userdefined':[100], 'userdefined2args':[100,100], 'userdefined3args':[100,100,100], @@ -651,29 +651,29 @@ TEMPLATES = {'t1x1': (0.5, 0.5, 0.0625, 0.125, 1.05, 0), # Names for blocks without names for popup help # SPECIAL_NAMES = { - 'audio':_('audio'), + 'audio':' ', 'division2':_('divide'), 'equal2':_('equal'), 'greater2':_('greater than'), - 'hspace':_('horizontal space'), + 'hspace':' ', 'identity2':_('identity'), 'if':_('if then'), - 'ifelse':_('if then else'), + 'ifelse':' ', 'journal':_('journal'), 'less2':_('less than'), 'minus2':_('minus'), - 'nop':_('Python code'), + 'nop':' ', 'number':_('number'), 'plus2':_('plus'), 'product2':_('multiply'), 'sqrt':_('square root'), - 'template1x1':_('presentation 1x1'), - 'template1x1a':_('presentation 1x1'), - 'template1x2':_('presentation 1x2'), - 'template2x1':_('presentation 2x1'), - 'template2x2':_('presentation 2x2'), - 'templatelist':_('presentation bulleted list'), - 'textsize':_('text size'), + 'template1x1':' ', + 'template1x1a':' ', + 'template1x2':' ', + 'template2x1':' ', + 'template2x2':' ', + 'templatelist':' ', + 'textsize':' ', 'vspace':_('vertical space')} # @@ -738,14 +738,14 @@ MACROS = { [10, ['number', '1'], 0, 0, [9, None]]], 'picturelist': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('bulleted list')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setxy', 0, 0, [7, 10, 11, 12]], [10, 'leftx', 0, 0, [9, None]], [11, 'topy', 0, 0, [9, None]], @@ -757,14 +757,14 @@ MACROS = { [17, 'sandwichbottom', 0, 0, [14, None]]], 'picture1x1a': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('picture')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setscale', 0, 0, [7, 10, 11]], [10, ['number', '90'], 0, 0, [9, None]], [11, 'setxy', 0, 0, [9, 12, 13, 14]], @@ -775,14 +775,14 @@ MACROS = { [16, 'sandwichbottom', 0, 0, [14, None]]], 'picture2x2': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('2×2 pictures')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setscale', 0, 0, [7, 10, 11]], [10, ['number', '35'], 0, 0, [9, None]], [11, 'setxy', 0, 0, [9, 12, 13, 14]], @@ -808,14 +808,14 @@ MACROS = { [31, 'sandwichbottom', 0, 0, [29, None]]], 'picture2x1': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('2×1 pictures')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setscale', 0, 0, [7, 10, 11]], [10, ['number', '35'], 0, 0, [9, None]], [11, 'setxy', 0, 0, [9, 12, 13, 14]], @@ -841,14 +841,14 @@ MACROS = { [31, 'sandwichbottom', 0, 0, [29, None]]], 'picture1x2': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('1×2 pictures')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setscale', 0, 0, [7, 10, 11]], [10, ['number', '35'], 0, 0, [9, None]], [11, 'setxy', 0, 0, [9, 12, 13, 14]], @@ -874,14 +874,14 @@ MACROS = { [31, 'sandwichbottom', 0, 0, [29, None]]], 'picture1x1': [[0, 'sandwichtop', 0, 0, [None, 1, 2]], - [1, ['string', _('1×1 pictures')], 0, 0, [0, None]], + [1, ['string', ' '], 0, 0, [0, None]], [2, 'setxy', 0, 0, [0, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], [4, 'titley', 0, 0, [2, None]], [5, 'setscale', 0, 0, [2, 6, 7]], [6, ['number', '100'], 0, 0, [5, None]], [7, 'show', 0, 0, [5, 8, 9]], - [8, ['string',_('Title')], 0, 0, [7, None]], + [8, ['string',' '], 0, 0, [7, None]], [9, 'setscale', 0, 0, [7, 10, 11]], [10, ['number', '35'], 0, 0, [9, None]], [11, 'setxy', 0, 0, [9, 12, 13, 14]], @@ -263,6 +263,7 @@ class LogoCode: 'clean':[0, lambda self: self.prim_clear()], 'clearheap':[0, lambda self: self.empty_heap()], 'color':[0, lambda self: self.tw.canvas.color], + 'gray':[0, lambda self: self.tw.canvas.gray], 'comment':[1, lambda self, x: self.prim_print(x, True)], 'container':[1, lambda self,x: x], 'cyan':[0, lambda self: 50], @@ -322,6 +323,7 @@ class LogoCode: 'savesvg':[1, lambda self, x: self.save_svg(x)], 'scale':[0, lambda self: self.scale], 'setcolor':[1, lambda self, x: self.tw.canvas.setcolor(x)], + 'setgray':[1, lambda self, x: self.tw.canvas.setgray(x)], 'seth':[1, lambda self, x: self.tw.canvas.seth(x)], 'setpensize':[1, lambda self, x: self.tw.canvas.setpensize(x)], 'setscale':[1, lambda self, x: self.set_scale(x)], diff --git a/taturtle.py b/taturtle.py index b6fc6a9..4eaa72f 100644 --- a/taturtle.py +++ b/taturtle.py @@ -112,6 +112,7 @@ class Turtle: self.heading = 0 self.pen_shade = 50 self.pen_color = 0 + self.pen_gray = 100 self.pen_size = 5 self.pen_state = True @@ -139,6 +140,10 @@ class Turtle: """ Set the pen color for this turtle. """ self.pen_color = color + def set_gray(self, gray): + """ Set the pen gray level for this turtle. """ + self.pen_gray = gray + def set_shade(self, shade): """ Set the pen shade for this turtle. """ self.pen_shade = shade @@ -182,6 +187,10 @@ class Turtle: """ Return the turtle's color. """ return(self.pen_color) + def get_gray(self): + """ Return the turtle's gray level. """ + return(self.pen_gray) + def get_shade(self): """ Return the turtle's shade. """ return(self.pen_shade) |