Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
 summaryrefslogtreecommitdiffstats log msg author committer range
path: root/TurtleArt/tacanvas.py
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiff
Diffstat (limited to 'TurtleArt/tacanvas.py')
-rw-r--r--TurtleArt/tacanvas.py44
1 files changed, 35 insertions, 9 deletions
 diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.pyindex 0f110bf..d0b58e2 100644--- a/TurtleArt/tacanvas.py+++ b/TurtleArt/tacanvas.py@@ -42,18 +42,29 @@ def wrap100(n): return n -def calc_shade(c, s):+def calc_shade(c, s, invert=False): """ Convert a color to the current shade (lightness/darkness). """- if s < 0:- return int(c * (1 + s * 0.8))- return int(c + (65536 - c) * s * 0.9)---def calc_gray(c, g):+ # Assumes 16 bit input values+ if invert:+ if s < 0:+ return int(c / (1 + s * 0.8))+ return int((c - 65536 * s * 0.9) / (1 - (s * 0.9)))+ else:+ if s < 0:+ return int(c * (1 + s * 0.8))+ return int(c + (65536 - c) * s * 0.9)+++def calc_gray(c, g, invert=False): """ Gray is a psuedo saturation calculation. """+ # Assumes 16 bit input values if g == 100: return c- return int(((c * g) + (32768 * (100 - g))) / 100)+ if invert:+ return int(((c * 100) - (32768 * (100 - g))) / g)+ else:+ return int(((c * g) + (32768 * (100 - g))) / 100)+ colors = {} DEGTOR = 2 * pi / 360@@ -568,7 +579,22 @@ class TurtleGraphics: def get_color_index(self, r, g, b, a=0): """ Find the closest palette entry to the rgb triplet """- # TODO: Take into account gray and shade levels+ if self.shade != 50 or self.gray != 100:+ r <<= 8+ g <<= 8+ b <<= 8+ if self.shade != 50:+ sh = (wrap100(self.shade) - 50) / 50.0+ r = calc_shade(r, sh, True)+ g = calc_shade(g, sh, True)+ b = calc_shade(b, sh, True)+ if self.gray != 100:+ r = calc_gray(r, self.gray, True)+ g = calc_gray(g, self.gray, True)+ b = calc_gray(b, self.gray, True)+ r >>= 8+ g >>= 8+ b >>= 8 min_distance = 1000000 closest_color = -1 for i, c in enumerate(color_table):