Code

e27970e523e8128d0f2cc16130ae9048b5681562
[inkscape.git] / share / extensions / color_randomize.py
1 #!/usr/bin/env python
2 import coloreffect,random,inkex
4 class C(coloreffect.ColorEffect):
5     def __init__(self):
6         coloreffect.ColorEffect.__init__(self)
7         self.OptionParser.add_option("-x", "--hue",
8             action="store", type="inkbool", 
9             dest="hue", default=True,
10             help="randomize hue")
11         self.OptionParser.add_option("-s", "--saturation",
12             action="store", type="inkbool", 
13             dest="saturation", default=True,
14             help="randomize saturation")
15         self.OptionParser.add_option("-l", "--lightness",
16             action="store", type="inkbool", 
17             dest="lightness", default=True,
18             help="randomize lightness")
20     def colmod(self,r,g,b):
21         hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0)
22         if(self.options.hue):
23             hsl[0]=random.random()
24         if(self.options.saturation):
25             hsl[1]=random.random()
26         if(self.options.lightness):
27             hsl[2]=random.random()
28         rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2])
29         return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255)
31 c = C()
32 c.affect()
35 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99