diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-03-02 19:47:26 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-03-02 19:47:26 +0000 |
| commit | b3f002153bce861dd2f86fb02da66725c644459e (patch) | |
| tree | 8531aef7e793be1a2d811fe2a6605f8d24b675bd | |
| parent | Fix bug 1540155: Interactive simplify on pencit tool is hard to edit (diff) | |
| download | inkscape-b3f002153bce861dd2f86fb02da66725c644459e.tar.gz inkscape-b3f002153bce861dd2f86fb02da66725c644459e.zip | |
Fix bug: 1552003 Randomize color extension has no limits
Fixed bugs:
- https://launchpad.net/bugs/1552003
(bzr r14680)
| -rw-r--r-- | share/extensions/color_randomize.inx | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | share/extensions/color_randomize.py | 58 |
2 files changed, 57 insertions, 7 deletions
diff --git a/share/extensions/color_randomize.inx b/share/extensions/color_randomize.inx index 82691f0f4..0c84227ae 100644 --- a/share/extensions/color_randomize.inx +++ b/share/extensions/color_randomize.inx @@ -8,11 +8,15 @@ <param name="tab" type="notebook"> <page name="Options" _gui-text="Options"> <param name="hue" type="boolean" _gui-text="Hue">true</param> + <param name="hue_range" type="int" appearance="full" min="0" max="100" indent="0" _gui-text="Hue range (%)">100</param> <param name="saturation" type="boolean" _gui-text="Saturation">true</param> + <param name="saturation_range" type="int" appearance="full" min="0" max="100" indent="0" _gui-text="Saturation range (%)">100</param> <param name="lightness" type="boolean" _gui-text="Lightness">true</param> + <param name="lightness_range" type="int" appearance="full" min="0" max="100" indent="0" _gui-text="Lightness range (%)">100</param> + </page> <page name="Help" _gui-text="Help"> - <_param name="instructions" type="description" xml:space="preserve">Converts to HSL, randomizes hue and/or saturation and/or lightness and converts it back to RGB.</_param> + <_param name="instructions" type="description" xml:space="preserve">Converts to HSL, randomizes hue and/or saturation and/or lightness and converts it back to RGB. Lower the range values to limit the distance between the original color and the randomized one.</_param> </page> </param> <effect> diff --git a/share/extensions/color_randomize.py b/share/extensions/color_randomize.py index e939b7b6d..b8f52cb6b 100755..100644 --- a/share/extensions/color_randomize.py +++ b/share/extensions/color_randomize.py @@ -7,15 +7,27 @@ class C(coloreffect.ColorEffect): self.OptionParser.add_option("-x", "--hue", action="store", type="inkbool", dest="hue", default=True, - help="randomize hue") + help="Randomize hue") + self.OptionParser.add_option("-y", "--hue_range", + action="store", type="int", + dest="hue_range", default=0, + help="Hue range") self.OptionParser.add_option("-s", "--saturation", action="store", type="inkbool", dest="saturation", default=True, - help="randomize saturation") + help="Randomize saturation") + self.OptionParser.add_option("-t", "--saturation_range", + action="store", type="int", + dest="saturation_range", default=0, + help="Saturation range") self.OptionParser.add_option("-l", "--lightness", action="store", type="inkbool", dest="lightness", default=True, - help="randomize lightness") + help="Randomize lightness") + self.OptionParser.add_option("-m", "--lightness_range", + action="store", type="int", + dest="lightness_range", default=0, + help="Lightness range") self.OptionParser.add_option("--tab", action="store", type="string", dest="tab", @@ -23,12 +35,46 @@ class C(coloreffect.ColorEffect): def colmod(self,r,g,b): hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + if(self.options.hue): - hsl[0]=random.random() + limit = 255.0 * (1 + self.options.hue_range) / 100.0 + limit /= 2 + max = int((hsl[0] * 255.0) + limit) + min = int((hsl[0] * 255.0) - limit) + if max > 255: + min = min - (max - 255) + max = 255 + if min < 0: + max = max - min + min = 0 + hsl[0] = random.randrange(min, max) + hsl[0] /= 255.0 if(self.options.saturation): - hsl[1]=random.random() + limit = 255.0 * (1 + self.options.saturation_range) / 100.0 + limit /= 2 + max = int((hsl[1] * 255.0) + limit) + min = int((hsl[1] * 255.0) - limit) + if max > 255: + min = min - (max - 255) + max = 255 + if min < 0: + max = max - min + min = 0 + hsl[1] = random.randrange(min, max) + hsl[1] /= 255.0 if(self.options.lightness): - hsl[2]=random.random() + limit = 255.0 * (1 + self.options.lightness_range) / 100.0 + limit /= 2 + max = int((hsl[2] * 255.0) + limit) + min = int((hsl[2] * 255.0) - limit) + if max > 255: + min = min - (max - 255) + max = 255 + if min < 0: + max = max - min + min = 0 + hsl[2] = random.randrange(min, max) + hsl[2] /= 255.0 rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) |
