diff options
| author | bulia byak <buliabyak@gmail.com> | 2007-03-14 05:00:33 +0000 |
|---|---|---|
| committer | buliabyak <buliabyak@users.sourceforge.net> | 2007-03-14 05:00:33 +0000 |
| commit | d43d89fb797c0351ae5a6a14eb1d8d4c647571d4 (patch) | |
| tree | f04ca859f1f04ba2a5dc6a73995248ba00346369 /share | |
| parent | Swap out entities in tooltips. Fixes https://bugs.launchpad.net/ubuntu/+sour... (diff) | |
| download | inkscape-d43d89fb797c0351ae5a6a14eb1d8d4c647571d4.tar.gz inkscape-d43d89fb797c0351ae5a6a14eb1d8d4c647571d4.zip | |
spirograph
(bzr r2641)
Diffstat (limited to 'share')
| -rw-r--r-- | share/extensions/Makefile.am | 2 | ||||
| -rw-r--r-- | share/extensions/spirograph.inx | 24 | ||||
| -rw-r--r-- | share/extensions/spirograph.py | 115 |
3 files changed, 141 insertions, 0 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index f50465570..256133d03 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -72,6 +72,8 @@ extensions = \ simplestyle.py \ sk2svg.sh \ SpSVG.pm \ + spirograph.py\ + spirograph.inx\ straightseg.py \ summersnight.py \ svg_and_media_zip_output.py \ diff --git a/share/extensions/spirograph.inx b/share/extensions/spirograph.inx new file mode 100644 index 000000000..63ffa7c12 --- /dev/null +++ b/share/extensions/spirograph.inx @@ -0,0 +1,24 @@ +<inkscape-extension> + <_name>Spirograph</_name> + <id>org.ekips.filter.spirograph</id> + <dependency type="executable" location="extensions">spirograph.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <param name="primaryr" type="float" min="0.0" max="1000.0" _gui-text="R - Ring Radius (px)">100.0</param> + <param name="secondaryr" type="float" min="0.0" max="1000.0" _gui-text="r - Gear Radius (px)">60.0</param> + <param name="penr" type="float" min="0.0" max="1000.0" _gui-text="d - Pen Radius (px)">50.0</param> + <param name="gearplacement" type="optiongroup" _gui-text="Gear Placement"> + <option>Inside (Hypotrochoid)</option> + <option>Outside (Epitrochoid)</option> + </param> + <param name="rotation" type="float" min="-360.0" max="360.0" _gui-text="Rotation (deg)">0.0</param> + <param name="quality" type="int" min="1" max="100" _gui-text="Quality (Default = 16)">16</param> + <effect> + <object-type>all</object-type> + <effects-menu> + <submenu _name="Render"/> + </effects-menu> + </effect> + <script> + <command reldir="extensions" interpreter="python">spirograph.py</command> + </script> +</inkscape-extension> diff --git a/share/extensions/spirograph.py b/share/extensions/spirograph.py new file mode 100644 index 000000000..19b7ab870 --- /dev/null +++ b/share/extensions/spirograph.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python +''' +Copyright (C) 2007 Joel Holdsworth joel@airwebreathe.org.uk + +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 inkex, simplestyle, math + +class Spirograph(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-R", "--primaryr", + action="store", type="float", + dest="primaryr", default=60.0, + help="The radius of the outer gear") + self.OptionParser.add_option("-r", "--secondaryr", + action="store", type="float", + dest="secondaryr", default=100.0, + help="The radius of the inner gear") + self.OptionParser.add_option("-d", "--penr", + action="store", type="float", + dest="penr", default=50.0, + help="The distance of the pen from the inner gear") + self.OptionParser.add_option("-p", "--gearplacement", + action="store", type="string", + dest="gearplacement", default=50.0, + help="Selects whether the gear is inside or outside the ring") + self.OptionParser.add_option("-a", "--rotation", + action="store", type="float", + dest="rotation", default=100.0, + help="The number of degrees to rotate the image by") + self.OptionParser.add_option("-q", "--quality", + action="store", type="int", + dest="quality", default=16, + help="The quality of the calculated output") + def effect(self): + + if self.options.secondaryr == 0: + return + if self.options.quality == 0: + return + + if(self.options.gearplacement.strip(' ').lower().startswith('outside')): + a = self.options.primaryr + self.options.secondaryr + flip = -1 + else: + a = self.options.primaryr - self.options.secondaryr + flip = 1 + + ratio = a / self.options.secondaryr + if ratio == 0: + return + scale = 2 * math.pi / (ratio * self.options.quality) + + rotation = 2 * math.pi * self.options.rotation / 180; + + new = self.document.createElement('svg:path') + s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', + 'stroke-opacity': '1.0', 'fill-opacity': '1.0', + 'stroke': '#000000', 'stroke-linecap': 'butt', + 'fill': 'none'} + new.setAttribute('style', simplestyle.formatStyle(s)) + + pathString = '' + maxPointCount = 1000 + + for i in range(maxPointCount): + + theta = i * scale + + x = a * math.cos(theta + rotation) + \ + self.options.penr * math.cos(ratio * theta + rotation) * flip + \ + self.view_center[0] + y = a * math.sin(theta + rotation) - \ + self.options.penr * math.sin(ratio * theta + rotation) + \ + self.view_center[1] + + dx = (-a * math.sin(theta + rotation) - \ + ratio * self.options.penr * math.sin(ratio * theta + rotation) * flip) * scale / 3 + dy = (a * math.cos(theta + rotation) - \ + ratio * self.options.penr * math.cos(ratio * theta + rotation)) * scale / 3 + + if i <= 0: + pathString += 'M ' + str(x) + ',' + str(y) + ' C ' + str(x + dx) + ',' + str(y + dy) + ' ' + else: + pathString += str(x - dx) + ',' + str(y - dy) + ' ' + str(x) + ',' + str(y) + + if math.fmod(i / ratio, self.options.quality) == 0 and i % self.options.quality == 0: + pathString += 'Z' + break + else: + if i == maxPointCount - 1: + pass # we reached the allowed maximum of points, stop here + else: + pathString += ' C ' + str(x + dx) + ',' + str(y + dy) + ' ' + + + new.setAttribute('d', pathString) + self.current_layer.appendChild(new) + +e = Spirograph() +e.affect() + |
