1
1
#!/usr/bin/env python
2
import coloreffect,random,inkex
8
4
class C(coloreffect.ColorEffect):
10
6
coloreffect.ColorEffect.__init__(self)
7
self.OptionParser.add_option("-x", "--hue",
8
action="store", type="inkbool",
9
dest="hue", default=True,
11
11
self.OptionParser.add_option("-y", "--hue_range",
12
12
action="store", type="int",
13
13
dest="hue_range", default=0,
15
self.OptionParser.add_option("-s", "--saturation",
16
action="store", type="inkbool",
17
dest="saturation", default=True,
18
help="Randomize saturation")
15
19
self.OptionParser.add_option("-t", "--saturation_range",
16
20
action="store", type="int",
17
21
dest="saturation_range", default=0,
18
22
help="Saturation range")
23
self.OptionParser.add_option("-l", "--lightness",
24
action="store", type="inkbool",
25
dest="lightness", default=True,
26
help="Randomize lightness")
19
27
self.OptionParser.add_option("-m", "--lightness_range",
20
28
action="store", type="int",
21
29
dest="lightness_range", default=0,
22
30
help="Lightness range")
23
self.OptionParser.add_option("-o", "--opacity_range",
24
action="store", type="int",
25
dest="opacity_range", default=0,
27
31
self.OptionParser.add_option("--tab",
28
32
action="store", type="string",
30
34
help="The selected UI-tab when OK was pressed")
32
def randomize_hsl(self, limit, current_value):
33
limit = 255.0 * limit / 100.0
35
max = int((current_value * 255.0) + limit)
36
min = int((current_value * 255.0) - limit)
38
min = min - (max - 255)
43
return random.randrange(min, max) / 255.0
45
36
def colmod(self,r,g,b):
46
37
hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0)
47
if self.options.hue_range > 0:
48
hsl[0] = self.randomize_hsl(self.options.hue_range, hsl[0])
49
if self.options.saturation_range > 0:
50
hsl[1] = self.randomize_hsl(self.options.saturation_range, hsl[1])
51
if self.options.lightness_range > 0:
52
hsl[2] = self.randomize_hsl(self.options.lightness_range, hsl[2])
40
limit = 255.0 * (1 + self.options.hue_range) / 100.0
42
max = int((hsl[0] * 255.0) + limit)
43
min = int((hsl[0] * 255.0) - limit)
45
min = min - (max - 255)
50
hsl[0] = random.randrange(min, max)
52
if(self.options.saturation):
53
limit = 255.0 * (1 + self.options.saturation_range) / 100.0
55
max = int((hsl[1] * 255.0) + limit)
56
min = int((hsl[1] * 255.0) - limit)
58
min = min - (max - 255)
63
hsl[1] = random.randrange(min, max)
65
if(self.options.lightness):
66
limit = 255.0 * (1 + self.options.lightness_range) / 100.0
68
max = int((hsl[2] * 255.0) + limit)
69
min = int((hsl[2] * 255.0) - limit)
71
min = min - (max - 255)
76
hsl[2] = random.randrange(min, max)
53
78
rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2])
54
79
return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255)
56
def opacmod(self, opacity):
57
if self.options.opacity_range > 0:
58
# maybe not necessary, but better not change things that shouldn't change
60
opacity = float(opacity)
64
limit = self.options.opacity_range
66
max = opacity*100 + limit
67
min = opacity*100 - limit
69
min = min - (max - 100)
74
ret = str(random.uniform(min,max)/100)
79
if __name__ == '__main__':
84
85
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99