X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=share%2Fextensions%2Fwhirl.py;h=b2014191708785d791a56b77c38a26e45772b35f;hb=7635f139f805c57c99a6e35330312d5c7d093924;hp=35dbc0840bab7027118509fb3053efcd2c42045c;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/share/extensions/whirl.py b/share/extensions/whirl.py index 35dbc0840..b20141917 100644 --- a/share/extensions/whirl.py +++ b/share/extensions/whirl.py @@ -19,47 +19,47 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import math, inkex, cubicsuperpath class Whirl(inkex.Effect): - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("-x", "--centerx", - action="store", type="float", - dest="centerx", default=10.0, - help="") - self.OptionParser.add_option("-y", "--centery", - action="store", type="float", - dest="centery", default=0.0, - help="") - self.OptionParser.add_option("-t", "--whirl", - action="store", type="float", - dest="whirl", default=1.0, - help="amount of whirl") - self.OptionParser.add_option("-r", "--rotation", - action="store", type="inkbool", - dest="rotation", default=True, - help="direction of rotation") - def effect(self): - for id, node in self.selected.iteritems(): - rotation = 1 - if self.options.rotation == True: - rotation = -1 - whirl = self.options.whirl / 1000 - if node.tagName == 'path': - d = node.attributes.getNamedItem('d') - p = cubicsuperpath.parsePath(d.value) - for sub in p: - for csp in sub: - for point in csp: - point[0] -= self.options.centerx - point[1] -= self.options.centery - dist = math.sqrt((point[0] ** 2) + (point[1] ** 2)) - if dist != 0: - a = rotation * dist * whirl - theta = math.atan2(point[1], point[0]) + a - point[0] = (dist * math.cos(theta)) - point[1] = (dist * math.sin(theta)) - point[0] += self.options.centerx - point[1] += self.options.centery - d.value = cubicsuperpath.formatPath(p) + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-x", "--centerx", + action="store", type="float", + dest="centerx", default=10.0, + help="") + self.OptionParser.add_option("-y", "--centery", + action="store", type="float", + dest="centery", default=0.0, + help="") + self.OptionParser.add_option("-t", "--whirl", + action="store", type="float", + dest="whirl", default=1.0, + help="amount of whirl") + self.OptionParser.add_option("-r", "--rotation", + action="store", type="inkbool", + dest="rotation", default=True, + help="direction of rotation") + def effect(self): + for id, node in self.selected.iteritems(): + rotation = -1 + if self.options.rotation == True: + rotation = 1 + whirl = self.options.whirl / 1000 + if node.tagName == 'path': + d = node.attributes.getNamedItem('d') + p = cubicsuperpath.parsePath(d.value) + for sub in p: + for csp in sub: + for point in csp: + point[0] -= self.options.centerx + point[1] -= self.options.centery + dist = math.sqrt((point[0] ** 2) + (point[1] ** 2)) + if dist != 0: + a = rotation * dist * whirl + theta = math.atan2(point[1], point[0]) + a + point[0] = (dist * math.cos(theta)) + point[1] = (dist * math.sin(theta)) + point[0] += self.options.centerx + point[1] += self.options.centery + d.value = cubicsuperpath.formatPath(p) e = Whirl() e.affect()