Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_colorgamut_monchrome.py
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2010-01-31 16:44:47 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2010-01-31 16:44:47 (GMT)
commitc81c18ddf83a97147e1025129a65fe538c34acb7 (patch)
tree9ac7c2510bfe7dbcc4bf1bc73890cb3f4903c932 /ep_colorgamut_monchrome.py
parent5997b56f004cea4d7ee344f47e6ba2f41e10f119 (diff)
improving color scheme
Diffstat (limited to 'ep_colorgamut_monchrome.py')
-rw-r--r--ep_colorgamut_monchrome.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/ep_colorgamut_monchrome.py b/ep_colorgamut_monchrome.py
new file mode 100644
index 0000000..8bef90b
--- /dev/null
+++ b/ep_colorgamut_monchrome.py
@@ -0,0 +1,81 @@
+# coding: UTF-8
+# Copyright 2009 Thomas Jourdan
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Extension point for color constraints.
+This module handles a continuous red, green, blue and alpha color space."""
+
+import random
+import colorsys
+import model_random
+import model_locus
+import exon_color
+from gettext import gettext as _
+
+class MonochromeColorGamut(model_locus.Locus):
+ """Manages a series of monochromatic colors."""
+
+ def __init__(self, trunk):
+ """Color gamut constructor."""
+ super(MonochromeColorGamut, self).__init__(trunk)
+ self.hue = 0.0
+
+ def __eq__(self, other):
+ """Equality based on the gamuts components."""
+ equal = isinstance(other, MonochromeColorGamut) \
+ and self.hue == other.hue
+ return equal
+
+ def randomize(self):
+ """Set hue.
+ """
+ self.hue = random.random()
+
+ def get_randomized_color(self, path):
+ """Set red, green, blue and alpha to random values.
+ """
+ lightness = random.random()
+ saturation = random.random()
+ alpha = random.random()
+ rgb = colorsys.hls_to_rgb(self.hue, lightness, saturation)
+ return exon_color.Color(path, rgb[0], rgb[1], rgb[2], alpha)
+
+ def mutate(self):
+ """Make small random changes in hue.
+ """
+ self.hue = model_random.cyclic_limit(self.hue + model_random.jitter(0.1))
+
+ def mutate_color(self, color):
+ """Adjust rgba value to mutated hue.
+ pre: len(color.rgba) == 4
+ """
+ rgba = color.rgba
+ dummy, lightness, saturation = colorsys.rgb_to_hls( \
+ rgba[0], rgba[1], rgba[2])
+ rgb = colorsys.hls_to_rgb(self.hue, lightness, saturation)
+ color.rgba = (rgb[0], rgb[1], rgb[2], rgba[3])
+
+ def explain(self, formater):
+ formater.text_item('Monochromatic color scheme')
+
+ def copy(self):
+ """The MonochromeColorGamut copy constructor
+ # check for distinct references, needs to copy content, not references
+ post: __return__ is not self
+ """
+ new_one = MonochromeColorGamut(self.get_trunk())
+ new_one.hue = self.hue
+ return new_one