summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2007-01-15 23:09:11 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2007-01-15 23:09:11 +0000
commit58a53f3c1c75fc6141d611b01fd6f14db92e1b34 (patch)
tree49862dff765d85a1cfdb1cc8ac491e6897ab5910
parent(bzr r2215) (diff)
downloadinkscape-58a53f3c1c75fc6141d611b01fd6f14db92e1b34.tar.gz
inkscape-58a53f3c1c75fc6141d611b01fd6f14db92e1b34.zip
add fractalize extension
(bzr r2216)
-rw-r--r--share/extensions/Makefile.am2
-rwxr-xr-xshare/extensions/fractalize.inx17
-rwxr-xr-xshare/extensions/fractalize.py102
3 files changed, 121 insertions, 0 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am
index ad5f9d53b..f50465570 100644
--- a/share/extensions/Makefile.am
+++ b/share/extensions/Makefile.am
@@ -40,6 +40,7 @@ extensions = \
ffgeom.py\
fig2svg.sh \
flatten.py \
+ fractalize.py \
funcplot.py \
g2pngs.py\
gimp_xcf.py \
@@ -121,6 +122,7 @@ modules = \
extractimage.inx \
fig_input.inx \
flatten.inx \
+ fractalize.inx \
funcplot.inx \
g2pngs.inx\
gimp_xcf.inx \
diff --git a/share/extensions/fractalize.inx b/share/extensions/fractalize.inx
new file mode 100755
index 000000000..dde7b0048
--- /dev/null
+++ b/share/extensions/fractalize.inx
@@ -0,0 +1,17 @@
+<inkscape-extension>
+ <name>Fractalize</name>
+ <id>org.ekips.filter.fractalize</id>
+ <dependency type="executable" location="extensions">fractalize.py</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+ <param name="subdivs" type="int" gui-text="Subdivisions">6</param>
+ <param name="smooth" type="float" gui-text="Smoothness">4.0</param>
+ <effect>
+ <object-type>path</object-type>
+ <effects-menu>
+ <submenu _name="Modify Path"/>
+ </effects-menu>
+ </effect>
+ <script>
+ <command reldir="extensions" interpreter="python">fractalize.py</command>
+ </script>
+</inkscape-extension>
diff --git a/share/extensions/fractalize.py b/share/extensions/fractalize.py
new file mode 100755
index 000000000..7b4dc2ea3
--- /dev/null
+++ b/share/extensions/fractalize.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2005 Carsten Goetze c.goetze@tu-bs.de
+
+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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+'''
+import random, math, inkex, simplestyle, simplepath
+
+def calculateSubdivision(x1,y1,x2,y2,smoothness):
+ """ Calculate the vector from (x1,y1) to (x2,y2) """
+ x3 = x2 - x1
+ y3 = y2 - y1
+ """ Calculate the point half-way between the two points """
+ hx = x1 + x3/2
+ hy = y1 + y3/2
+ """ Calculate normalized vector perpendicular to the vector (x3,y3) """
+ length = math.sqrt(x3*x3 + y3*y3)
+ nx = -y3/length
+ ny = x3/length
+ """ Scale perpendicular vector by random factor """
+ r = random.uniform(-length/(1+smoothness),length/(1+smoothness))
+ nx = nx * r
+ ny = ny * r
+ """ add scaled perpendicular vector to the half-way point to get the final
+ displaced subdivision point """
+ x = hx + nx
+ y = hy + ny
+ return [x, y]
+
+class PathFractalize(inkex.Effect):
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ self.OptionParser.add_option("-s", "--subdivs",
+ action="store", type="int",
+ dest="subdivs", default="6",
+ help="Number of subdivisons")
+ self.OptionParser.add_option("-f", "--smooth",
+ action="store", type="float",
+ dest="smooth", default="4.0",
+ help="Smoothness of the subdivision")
+ def effect(self):
+ for id, node in self.selected.iteritems():
+ if node.tagName == 'path':
+ d = node.attributes.getNamedItem('d')
+ p = simplepath.parsePath(d.value)
+ new = self.document.createElement('svg:path')
+ try:
+ t = node.attributes.getNamedItem('transform').value
+ new.setAttribute('transform', t)
+ except AttributeError:
+ pass
+
+ s = simplestyle.parseStyle(node.attributes.getNamedItem('style').value)
+ new.setAttribute('style', simplestyle.formatStyle(s))
+
+ a = []
+ p = simplepath.parsePath(node.attributes.getNamedItem('d').value)
+ first = 1
+ for cmd,params in p:
+ if cmd != 'Z':
+ if first == 1:
+ x1 = params[-2]
+ y1 = params[-1]
+ a.append(['M',params[-2:]])
+ first = 2
+ else :
+ x2 = params[-2]
+ y2 = params[-1]
+ self.fractalize(a,x1,y1,x2,y2,self.options.subdivs,self.options.smooth)
+ x1 = x2
+ y1 = y2
+ a.append(['L',params[-2:]])
+
+ new.setAttribute('d', simplepath.formatPath(a))
+ node.parentNode.appendChild(new)
+ node.parentNode.removeChild(node)
+
+ def fractalize(self,a,x1,y1,x2,y2,s,f):
+ subdivPoint = calculateSubdivision(x1,y1,x2,y2,f)
+
+ if s > 0 :
+ """ recursively subdivide the segment left of the subdivision point """
+ self.fractalize(a,x1,y1,subdivPoint[-2],subdivPoint[-1],s-1,f)
+ a.append(['L',subdivPoint])
+ """ recursively subdivide the segment right of the subdivision point """
+ self.fractalize(a,subdivPoint[-2],subdivPoint[-1],x2,y2,s-1,f)
+
+e = PathFractalize()
+e.affect()
+