Code

get the CORRECT Sodipodi namespace in there
[inkscape.git] / share / extensions / whirl.py
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("-x", "--centerx",
25                                                 action="store", type="float", 
26                                                 dest="centerx", default=10.0,
27                                                 help="")
28                 self.OptionParser.add_option("-y", "--centery",
29                                                 action="store", type="float", 
30                                                 dest="centery", default=0.0,
31                                                 help="")
32                 self.OptionParser.add_option("-t", "--whirl",
33                                                 action="store", type="float", 
34                                                 dest="whirl", default=1.0,
35                                                 help="amount of whirl")
36                 self.OptionParser.add_option("-r", "--rotation",
37                                                 action="store", type="inkbool", 
38                                                 dest="rotation", default=True,
39                                                 help="direction of rotation")
40         def effect(self):
41                 for id, node in self.selected.iteritems():
42                         rotation = -1
43                         if self.options.rotation == True:
44                                 rotation = 1
45                         whirl = self.options.whirl / 1000
46                         if node.tagName == 'path':
47                                 d = node.attributes.getNamedItem('d')
48                                 p = cubicsuperpath.parsePath(d.value)
49                                 for sub in p:
50                                         for csp in sub:
51                                                 for point in csp:
52                                                         point[0] -= self.options.centerx
53                                                         point[1] -= self.options.centery
54                                                         dist = math.sqrt((point[0] ** 2) + (point[1] ** 2))
55                                                         if dist != 0:
56                                                                 a = rotation * dist * whirl
57                                                                 theta = math.atan2(point[1], point[0]) + a
58                                                                 point[0] = (dist * math.cos(theta))
59                                                                 point[1] = (dist * math.sin(theta))
60                                                         point[0] += self.options.centerx
61                                                         point[1] += self.options.centery
62                                 d.value = cubicsuperpath.formatPath(p)
64 e = Whirl()
65 e.affect()