From f96a7eb3f99d0893ddb1e07bd1d9853737e9b033 Mon Sep 17 00:00:00 2001 From: ajuanpi <> Date: Tue, 24 May 2016 15:23:46 +0200 Subject: [Bug #1071833] major update of Jitter Nodes extension. Fixed bugs: - https://launchpad.net/bugs/1071833 (bzr r14912) --- po/POTFILES.in | 5 +- share/extensions/jitternodes.inx | 33 +++++++++ share/extensions/jitternodes.py | 109 ++++++++++++++++++++++++++++++ share/extensions/radiusrand.inx | 28 -------- share/extensions/radiusrand.py | 85 ----------------------- share/extensions/test/jitternodes.test.py | 26 +++++++ share/extensions/test/radiusrand.test.py | 26 ------- 7 files changed, 170 insertions(+), 142 deletions(-) create mode 100644 share/extensions/jitternodes.inx create mode 100755 share/extensions/jitternodes.py delete mode 100644 share/extensions/radiusrand.inx delete mode 100755 share/extensions/radiusrand.py create mode 100755 share/extensions/test/jitternodes.test.py delete mode 100755 share/extensions/test/radiusrand.test.py diff --git a/po/POTFILES.in b/po/POTFILES.in index 1dfd26eb1..f760c718c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,6 +1,6 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. -# Generated by ./generate_POTFILES.sh at Thu Apr 14 04:25:58 CEST 2016 +# Generated by ./generate_POTFILES.sh at Mon May 23 11:59:28 CEST 2016 [encoding: UTF-8] inkscape.appdata.xml.in inkscape.desktop.in @@ -148,7 +148,6 @@ src/live_effects/lpe-interpolate_points.cpp src/live_effects/lpe-jointype.cpp src/live_effects/lpe-knot.cpp src/live_effects/lpe-lattice2.cpp -src/live_effects/lpe-mirror_symmetry.cpp src/live_effects/lpe-patternalongpath.cpp src/live_effects/lpe-perspective-envelope.cpp src/live_effects/lpe-powerstroke.cpp @@ -524,6 +523,7 @@ share/extensions/wireframe_sphere.py [type: gettext/xml] share/extensions/jessyInk_uninstall.inx [type: gettext/xml] share/extensions/jessyInk_video.inx [type: gettext/xml] share/extensions/jessyInk_view.inx +[type: gettext/xml] share/extensions/jitternodes.inx [type: gettext/xml] share/extensions/layers2svgfont.inx [type: gettext/xml] share/extensions/layout_nup.inx [type: gettext/xml] share/extensions/lindenmayer.inx @@ -549,7 +549,6 @@ share/extensions/wireframe_sphere.py [type: gettext/xml] share/extensions/print_win32_vector.inx [type: gettext/xml] share/extensions/printing_marks.inx [type: gettext/xml] share/extensions/ps_input.inx -[type: gettext/xml] share/extensions/radiusrand.inx [type: gettext/xml] share/extensions/render_alphabetsoup.inx [type: gettext/xml] share/extensions/render_barcode.inx [type: gettext/xml] share/extensions/render_barcode_datamatrix.inx diff --git a/share/extensions/jitternodes.inx b/share/extensions/jitternodes.inx new file mode 100644 index 000000000..817fbd276 --- /dev/null +++ b/share/extensions/jitternodes.inx @@ -0,0 +1,33 @@ + + + <_name>Jitter nodes + org.ekips.filter.jitternodes + jitternodes.py + inkex.py + + + 10.0 + 10.0 + true + false + + <_item value="Uniform">Uniform + <_item value="Pareto">Pareto + <_item value="Gaussian">Gaussian + <_item value="Lognorm">Log-normal + + + + <_param name="title" type="description">This effect randomly shifts the nodes (and optionally node handles) of the selected path. + + + + path + + + + + + diff --git a/share/extensions/jitternodes.py b/share/extensions/jitternodes.py new file mode 100755 index 000000000..d6f5ce36d --- /dev/null +++ b/share/extensions/jitternodes.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +''' +Copyright (C) 2012 Juan Pablo Carbajal ajuanpi-dev@gmail.com +Copyright (C) 2005 Aaron Spike, aaron@ekips.org + +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 Street, Fifth Floor, Boston, MA 02110-1301, USA. +''' +import random, math, inkex, cubicsuperpath + +def randomize((x, y), rx, ry, dist): + + if dist == "Gaussian": + r1 = random.gauss(0.0,rx) + r2 = random.gauss(0.0,ry) + elif dist == "Pareto": + ''' + sign is used ot fake a double sided pareto distribution. + for parameter value between 1 and 2 the distribution has infinite variance + I truncate the distribution to a high value and then normalize it. + The idea is to get spiky distributions, any distribution with long-tails is + good (ideal would be Levy distribution). + ''' + sign = random.uniform(-1.0,1.0) + + r1 = min(random.paretovariate(1.0), 20.0)/20.0 + r2 = min(random.paretovariate(1.0), 20.0)/20.0 + + r1 = rx * math.copysign(r1, sign) + r2 = ry * math.copysign(r2, sign) + elif dist == "Lognorm": + sign = random.uniform(-1.0,1.0) + r1 = rx * math.copysign(random.lognormvariate(0.0,1.0)/3.5,sign) + r2 = ry * math.copysign(random.lognormvariate(0.0,1.0)/3.5,sign) + elif dist == "Uniform": + r1 = random.uniform(-rx,rx) + r2 = random.uniform(-ry,ry) + + x += r1 + y += r2 + + return [x, y] + +class JitterNodes(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("--title") + self.OptionParser.add_option("-x", "--radiusx", + action="store", type="float", + dest="radiusx", default=10.0, + help="Randomly move nodes and handles within this radius, X") + self.OptionParser.add_option("-y", "--radiusy", + action="store", type="float", + dest="radiusy", default=10.0, + help="Randomly move nodes and handles within this radius, Y") + self.OptionParser.add_option("-c", "--ctrl", + action="store", type="inkbool", + dest="ctrl", default=True, + help="Randomize control points") + self.OptionParser.add_option("-e", "--end", + action="store", type="inkbool", + dest="end", default=True, + help="Randomize nodes") + self.OptionParser.add_option("-d", "--dist", + action="store", type="string", + dest="dist", default="Uniform", + help="Choose the distribution of the displacements") + self.OptionParser.add_option("--tab", + action="store", type="string", + dest="tab", + help="The selected UI-tab when OK was pressed") + + def effect(self): + for id, node in self.selected.iteritems(): + if node.tag == inkex.addNS('path','svg'): + d = node.get('d') + p = cubicsuperpath.parsePath(d) + for subpath in p: + for csp in subpath: + if self.options.end: + delta=randomize([0,0], self.options.radiusx, self.options.radiusy, self.options.dist) + csp[0][0]+=delta[0] + csp[0][1]+=delta[1] + csp[1][0]+=delta[0] + csp[1][1]+=delta[1] + csp[2][0]+=delta[0] + csp[2][1]+=delta[1] + if self.options.ctrl: + csp[0]=randomize(csp[0], self.options.radiusx, self.options.radiusy, self.options.dist) + csp[2]=randomize(csp[2], self.options.radiusx, self.options.radiusy, self.options.dist) + node.set('d',cubicsuperpath.formatPath(p)) + +if __name__ == '__main__': + e = JitterNodes() + e.affect() + + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 diff --git a/share/extensions/radiusrand.inx b/share/extensions/radiusrand.inx deleted file mode 100644 index 38e7d6c4c..000000000 --- a/share/extensions/radiusrand.inx +++ /dev/null @@ -1,28 +0,0 @@ - - - <_name>Jitter nodes - org.ekips.filter.radiusrand - radiusrand.py - inkex.py - - - 10.0 - 10.0 - true - false - true - - - <_param name="title" type="description">This effect randomly shifts the nodes (and optionally node handles) of the selected path. - - - - path - - - - - - diff --git a/share/extensions/radiusrand.py b/share/extensions/radiusrand.py deleted file mode 100755 index e4585ccd4..000000000 --- a/share/extensions/radiusrand.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python -''' -Copyright (C) 2005 Aaron Spike, aaron@ekips.org - -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 2 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. -''' -import random, math, inkex, cubicsuperpath - -def randomize((x, y), rx, ry, norm): - if norm: - r = abs(random.normalvariate(0.0,0.5*max(rx, ry))) - else: - r = random.uniform(0.0,max(rx, ry)) - a = random.uniform(0.0,2*math.pi) - x += math.cos(a)*rx - y += math.sin(a)*ry - return [x, y] - -class RadiusRandomize(inkex.Effect): - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("--title") - self.OptionParser.add_option("-x", "--radiusx", - action="store", type="float", - dest="radiusx", default=10.0, - help="Randomly move nodes and handles within this radius, X") - self.OptionParser.add_option("-y", "--radiusy", - action="store", type="float", - dest="radiusy", default=10.0, - help="Randomly move nodes and handles within this radius, Y") - self.OptionParser.add_option("-c", "--ctrl", - action="store", type="inkbool", - dest="ctrl", default=True, - help="Randomize control points") - self.OptionParser.add_option("-e", "--end", - action="store", type="inkbool", - dest="end", default=True, - help="Randomize nodes") - self.OptionParser.add_option("-n", "--norm", - action="store", type="inkbool", - dest="norm", default=True, - help="Use normal distribution") - self.OptionParser.add_option("--tab", - action="store", type="string", - dest="tab", - help="The selected UI-tab when OK was pressed") - - def effect(self): - for id, node in self.selected.iteritems(): - if node.tag == inkex.addNS('path','svg'): - d = node.get('d') - p = cubicsuperpath.parsePath(d) - for subpath in p: - for csp in subpath: - if self.options.end: - delta=randomize([0,0], self.options.radiusx, self.options.radiusy, self.options.norm) - csp[0][0]+=delta[0] - csp[0][1]+=delta[1] - csp[1][0]+=delta[0] - csp[1][1]+=delta[1] - csp[2][0]+=delta[0] - csp[2][1]+=delta[1] - if self.options.ctrl: - csp[0]=randomize(csp[0], self.options.radiusx, self.options.radiusy, self.options.norm) - csp[2]=randomize(csp[2], self.options.radiusx, self.options.radiusy, self.options.norm) - node.set('d',cubicsuperpath.formatPath(p)) - -if __name__ == '__main__': - e = RadiusRandomize() - e.affect() - - -# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 diff --git a/share/extensions/test/jitternodes.test.py b/share/extensions/test/jitternodes.test.py new file mode 100755 index 000000000..699752af2 --- /dev/null +++ b/share/extensions/test/jitternodes.test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +# This is only the automatic generated test file for ../jitternodes.py +# This must be filled with real tests and this commentary +# must be cleared. +# If you want to help, read the python unittest documentation: +# http://docs.python.org/library/unittest.html + +import sys +sys.path.append('..') # this line allows to import the extension code + +import unittest +from jitternodes import * + +class JitterNodesBasicTest(unittest.TestCase): + + #def setUp(self): + + def test_run_without_parameters(self): + args = [ 'minimal-blank.svg' ] + e = JitterNodes() + e.affect( args, False ) + #self.assertEqual( e.something, 'some value', 'A commentary about that.' ) + +if __name__ == '__main__': + unittest.main() diff --git a/share/extensions/test/radiusrand.test.py b/share/extensions/test/radiusrand.test.py deleted file mode 100755 index 99cb2972b..000000000 --- a/share/extensions/test/radiusrand.test.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -# This is only the automatic generated test file for ../radiusrand.py -# This must be filled with real tests and this commentary -# must be cleared. -# If you want to help, read the python unittest documentation: -# http://docs.python.org/library/unittest.html - -import sys -sys.path.append('..') # this line allows to import the extension code - -import unittest -from radiusrand import * - -class RadiusRandomizeBasicTest(unittest.TestCase): - - #def setUp(self): - - def test_run_without_parameters(self): - args = [ 'minimal-blank.svg' ] - e = RadiusRandomize() - e.affect( args, False ) - #self.assertEqual( e.something, 'some value', 'A commentary about that.' ) - -if __name__ == '__main__': - unittest.main() -- cgit v1.2.3