1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env python
'''
Copyright (C) 2006 Jean-Francois Barraud, barraud@math.univ-lille1.fr
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
barraud@math.univ-lille1.fr
'''
import inkex, cubicsuperpath, bezmisc, pathmodifier
import copy, math, re
class RubberStretch(pathmodifier.Diffeo):
def __init__(self):
pathmodifier.Diffeo.__init__(self)
self.OptionParser.add_option("-r", "--ratio",
action="store", type="float",
dest="ratio", default=0.5)
self.OptionParser.add_option("-c", "--curve",
action="store", type="float",
dest="curve", default=0.5)
def applyDiffeo(self,bpt,vects=()):
for v in vects:
v[0]-=bpt[0]
v[1]-=bpt[1]
v[1]*=-1
bpt[1]*=-1
a=self.options.ratio/100
b=min(self.options.curve/100,0.99)
x0= (self.bbox[0]+self.bbox[1])/2
y0=-(self.bbox[2]+self.bbox[3])/2
w,h=(self.bbox[1]-self.bbox[0])/2,(self.bbox[3]-self.bbox[2])/2
x,y=(bpt[0]-x0),(bpt[1]-y0)
sx=(1+b*(x/w+1)*(x/w-1))*2**(-a)
sy=(1+b*(y/h+1)*(y/h-1))*2**(-a)
bpt[0]=x0+x*sy
bpt[1]=y0+y/sx
for v in vects:
dx,dy=v
dXdx=sy
dXdy= x*2*b*y/h/h*2**(-a)
dYdx=-y*2*b*x/w/w*2**(-a)/sx/sx
dYdy=1/sx
v[0]=dXdx*dx+dXdy*dy
v[1]=dYdx*dx+dYdy*dy
#--spherify
#s=((x*x+y*y)/(w*w+h*h))**(-a/2)
#bpt[0]=x0+s*x
#bpt[1]=y0+s*y
#for v in vects:
# dx,dy=v
# v[0]=(1-a/2/(x*x+y*y)*2*x*x)*s*dx+( -a/2/(x*x+y*y)*2*y*x)*s*dy
# v[1]=( -a/2/(x*x+y*y)*2*x*y)*s*dx+(1-a/2/(x*x+y*y)*2*y*y)*s*dy
for v in vects:
v[0]+=bpt[0]
v[1]+=bpt[1]
v[1]*=-1
bpt[1]*=-1
e = RubberStretch()
e.affect()
|