1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2005 Aaron Spike, aaron@ekips.org
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
19 import math, inkex, cubicsuperpath
21 class Whirl(inkex.Effect):
22 def __init__(self):
23 inkex.Effect.__init__(self)
24 self.OptionParser.add_option("-t", "--whirl",
25 action="store", type="float",
26 dest="whirl", default=1.0,
27 help="amount of whirl")
28 self.OptionParser.add_option("-r", "--rotation",
29 action="store", type="inkbool",
30 dest="rotation", default=True,
31 help="direction of rotation")
32 def effect(self):
33 for id, node in self.selected.iteritems():
34 rotation = -1
35 if self.options.rotation == True:
36 rotation = 1
37 whirl = self.options.whirl / 1000
38 if node.tag == inkex.addNS('path','svg'):
39 d = node.get('d')
40 p = cubicsuperpath.parsePath(d)
41 for sub in p:
42 for csp in sub:
43 for point in csp:
44 point[0] -= self.view_center[0]
45 point[1] -= self.view_center[1]
46 dist = math.sqrt((point[0] ** 2) + (point[1] ** 2))
47 if dist != 0:
48 a = rotation * dist * whirl
49 theta = math.atan2(point[1], point[0]) + a
50 point[0] = (dist * math.cos(theta))
51 point[1] = (dist * math.sin(theta))
52 point[0] += self.view_center[0]
53 point[1] += self.view_center[1]
54 node.set('d',cubicsuperpath.formatPath(p))
56 if __name__ == '__main__':
57 e = Whirl()
58 e.affect()
61 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99