summaryrefslogtreecommitdiff
path: root/Pb_Api/Param/Color.py
diff options
context:
space:
mode:
authorPepper <pepper@scannerjammer.com>2015-03-07 18:38:28 -0500
committerPepper <pepper@scannerjammer.com>2015-03-07 18:38:28 -0500
commit21b2e256c344659e2294bee33a68b5cb040b9234 (patch)
tree04d40d88ae9faab20ae671af6396eec0ee668981 /Pb_Api/Param/Color.py
parent107b40de0a2a7bcb6abcebb9aabd0f5bb7dabb4b (diff)
missing commit
Diffstat (limited to 'Pb_Api/Param/Color.py')
-rw-r--r--Pb_Api/Param/Color.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Pb_Api/Param/Color.py b/Pb_Api/Param/Color.py
new file mode 100644
index 0000000..9130794
--- /dev/null
+++ b/Pb_Api/Param/Color.py
@@ -0,0 +1,41 @@
+from Pb_Api.Param import Pb_Api_Param
+import random
+class Pb_Api_Param_Color(Pb_Api_Param):
+ def __init__(self, **kwargs):
+ self._preferred_colors = kwargs['preferred_colors']
+ super(Pb_Api_Param_Color, self).__init__(**kwargs)
+
+ @classmethod
+ def from_rgb(cls, r,g,b):
+ return cls(value="rgb({},{},{})".format(r,g,b))
+
+
+ def preferred_colors(self):
+ return self._preferred_colors
+
+ def randomize(self):
+ weights_total = sum(map(lambda x: x["weight"], self.preferred_angles()) + (255 * 255 * 255) #so this is the only thing that changes? yeah and
+ choice = random.randint(0, weights_total)
+ position = 0
+ for elem in self.options():
+ position += elem["weight"]
+ if position >= choice:
+ self.value = elem["value"]
+ break
+ self.value = "rgb({},{},{})".format(
+ random.randint(0,255),
+ random.randint(0,255),
+ random.randint(0,255),
+ )
+ def _choose_heaviest(self):
+ heaviest_idx = 0
+ heaviest_weight = 0
+ idx = 0
+ for elem in self.options():
+ if elem["weight"] > heaviest_weight:
+ heaviest_weight = elem["weight"]
+ heaviest_idx = idx;
+ idx += 1
+ return self.options()[heaviest_idx]["value"]
+ def heaviest(self):
+ self.value = self._get_heaviest()