Commit f96a7eb3 authored by ajuanpi's avatar ajuanpi Committed by Nicolas Dufour

[Bug #1071833] major update of Jitter Nodes extension.

Fixed bugs:

(bzr r14912)
parent 2537dc68
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
# Generated by ./ at Thu Apr 14 04:25:58 CEST 2016
# Generated by ./ at Mon May 23 11:59:28 CEST 2016
[encoding: UTF-8]
......@@ -148,7 +148,6 @@ src/live_effects/lpe-interpolate_points.cpp
......@@ -524,6 +523,7 @@ share/extensions/
[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/
[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
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="">
<_name>Jitter nodes</_name>
<dependency type="executable" location="extensions"></dependency>
<dependency type="executable" location="extensions"></dependency>
<dependency type="executable" location="extensions"></dependency>
<param name="tab" type="notebook">
<page name="Options" _gui-text="Options">
......@@ -10,7 +10,12 @@
<param name="radiusy" type="float" min="0.0" max="1000.0" _gui-text="Maximum displacement in Y (px):">10.0</param>
<param name="end" type="boolean" _gui-text="Shift nodes">true</param>
<param name="ctrl" type="boolean" _gui-text="Shift node handles">false</param>
<param name="norm" type="boolean" _gui-text="Use normal distribution">true</param>
<param name="dist" type="enum" _gui-text="Distribution of the displacements:">
<_item value="Uniform">Uniform</_item>
<_item value="Pareto">Pareto</_item>
<_item value="Gaussian">Gaussian</_item>
<_item value="Lognorm">Log-normal</_item>
<page name="Help" _gui-text="Help">
<_param name="title" type="description">This effect randomly shifts the nodes (and optionally node handles) of the selected path.</_param>
......@@ -23,6 +28,6 @@
<command reldir="extensions" interpreter="python"></command>
<command reldir="extensions" interpreter="python"></command>
#!/usr/bin/env python
#!/usr/bin/env python
Copyright (C) 2012 Juan Pablo Carbajal
Copyright (C) 2005 Aaron Spike,
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
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,
......@@ -18,40 +19,63 @@ 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)))
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
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 RadiusRandomize(inkex.Effect):
class JitterNodes(inkex.Effect):
def __init__(self):
self.OptionParser.add_option("-x", "--radiusx",
action="store", type="float",
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",
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",
action="store", type="inkbool",
dest="ctrl", default=True,
help="Randomize control points")
self.OptionParser.add_option("-e", "--end",
action="store", type="inkbool",
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("-d", "--dist",
action="store", type="string",
dest="dist", default="Uniform",
help="Choose the distribution of the displacements")
action="store", type="string",
......@@ -65,20 +89,20 @@ class RadiusRandomize(inkex.Effect):
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)
delta=randomize([0,0], self.options.radiusx, self.options.radiusy, self.options.dist)
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)
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)
if __name__ == '__main__':
e = RadiusRandomize()
e = JitterNodes()
#!/usr/bin/env python
# This is only the automatic generated test file for ../
# This is only the automatic generated test file for ../
# This must be filled with real tests and this commentary
# must be cleared.
# If you want to help, read the python unittest documentation:
......@@ -10,15 +10,15 @@ import sys
sys.path.append('..') # this line allows to import the extension code
import unittest
from radiusrand import *
from jitternodes import *
class RadiusRandomizeBasicTest(unittest.TestCase):
class JitterNodesBasicTest(unittest.TestCase):
#def setUp(self):
def test_run_without_parameters(self):
args = [ 'minimal-blank.svg' ]
e = RadiusRandomize()
e = JitterNodes()
e.affect( args, False )
#self.assertEqual( e.something, 'some value', 'A commentary about that.' )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment