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

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

Fixed bugs:
  - https://launchpad.net/bugs/1071833

(bzr r14912)
parent 2537dc68
# 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
......
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Jitter nodes</_name>
<id>org.ekips.filter.radiusrand</id>
<dependency type="executable" location="extensions">radiusrand.py</dependency>
<id>org.ekips.filter.jitternodes</id>
<dependency type="executable" location="extensions">jitternodes.py</dependency>
<dependency type="executable" location="extensions">inkex.py</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>
</param>
</page>
<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 @@
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">radiusrand.py</command>
<command reldir="extensions" interpreter="python">jitternodes.py</command>
</script>
</inkscape-extension>
#!/usr/bin/env python
#!/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 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)))
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
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):
inkex.Effect.__init__(self)
self.OptionParser.add_option("--title")
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")
self.OptionParser.add_option("--tab",
action="store", type="string",
dest="tab",
......@@ -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)
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]
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.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)
node.set('d',cubicsuperpath.formatPath(p))
if __name__ == '__main__':
e = RadiusRandomize()
e = JitterNodes()
e.affect()
......
#!/usr/bin/env python
# This is only the automatic generated test file for ../radiusrand.py
# 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:
......@@ -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