diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-02-26 16:48:44 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-02-26 16:48:44 (GMT) |
commit | 6f21b8133cb583901810853b478a51fe6aaea311 (patch) | |
tree | 9fd37ab41f71f5c81df044f2e60f81be3e88d5eb /pysamples/set_rgb.py | |
parent | 2267a2997a2e03b5a2ff7830ec22b02ae57875e6 (diff) |
pep8 cleanup
Diffstat (limited to 'pysamples/set_rgb.py')
-rw-r--r-- | pysamples/set_rgb.py | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/pysamples/set_rgb.py b/pysamples/set_rgb.py index f524ec6..0a556fe 100644 --- a/pysamples/set_rgb.py +++ b/pysamples/set_rgb.py @@ -22,7 +22,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected and expanded to 3 arguments. -def myblock(lc, x): + +def myblock(lc, rgb_array): ########################################################################### # @@ -30,21 +31,15 @@ def myblock(lc, x): # ########################################################################### - # assuming x is an array [r, g, b] - b = int(x[2]) - while b < 0: - b += 256 - while b > 255: - b -= 256 - g = int(x[1]) - while g < 0: - g += 256 - while g > 255: - g -= 256 - r = int(x[0]) - while r < 0: - r += 256 - while r > 255: - r -= 256 - rgb = "#%02x%02x%02x" % (r,g,b) + def mod(x): + while x < 0: + x += 256 + while b > 255: + x -= 256 + return x + + b = mod(int(rgb_array[2])) + g = mod(int(rgb_array[1])) + r = mod(int(rgb_array[0])) + rgb = "#%02x%02x%02x" % (r, g, b) lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) |