summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f3f7b63)
raw | patch | inline | side by side (parent: f3f7b63)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Thu, 28 Dec 2006 14:27:30 +0000 (14:27 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Thu, 28 Dec 2006 14:27:30 +0000 (14:27 +0000) |
share/extensions/funcplot.inx | patch | blob | history | |
share/extensions/funcplot.py | patch | blob | history |
index 5c9ba6230dd760b5f354c4dbebc85d5fb7368274..6a6d740d1d7463f94914b77f3d66a1c4dca0060a 100644 (file)
<dependency type="executable" location="extensions">funcplot.py</dependency>\r
<dependency type="executable" location="extensions">inkex.py</dependency>\r
<param name="tab" type="notebook">\r
- <page name="sampling" _gui-text="Sampling">\r
+ <page name="sampling" _gui-text="Range and Sampling">\r
<param name="xstart" type="float" min="-1000.0" max="1000.0" _gui-text="Start x-value">0.0</param>\r
<param name="xend" type="float" min="-1000.0" max="1000.0" _gui-text="End x-value">1.0</param>\r
<param name="times2pi" type="boolean" _gui-text="Multiply x-range by 2*pi">false</param>\r
<param name="ybottom" type="float" min="-1000.0" max="1000.0" _gui-text="y-value of rectangle's bottom">0.0</param>\r
<param name="ytop" type="float" min="-1000.0" max="1000.0" _gui-text="y-value of rectangle's top">1.0</param>\r
<param name="samples" type="int" min="2" max="1000" _gui-text="Samples">8</param>\r
+ <param name="isoscale" type="boolean" _gui-text="Isotropic scaling (uses smallest: width/xrange or height/yrange)">false</param>\r
</page>\r
<page name="desc" _gui-text="Help">\r
<param name="pythonfunctions" type="description">The following functions are available:\r
(the available functions are the standard python math functions)\r
-ceil(x); fabs(x); floor(x); fmod(x,y); frexp(x); ldexp(x,i); modf(x); exp(x); log(x [, base]); log10(x); pow(x,y); sqrt(x); acos(x); asin(x); atan(x); atan2(y,x); cos(x); hypot(x,y); sin(x); tan(x); degrees(x); radians(x); cosh(x); sinh(x); tanh(x).\r
+ceil(x); fabs(x); floor(x); fmod(x,y); frexp(x); ldexp(x,i); \r
+modf(x); exp(x); log(x [, base]); log10(x); pow(x,y); sqrt(x); \r
+acos(x); asin(x); atan(x); atan2(y,x); hypot(x,y); \r
+cos(x); sin(x); tan(x); degrees(x); radians(x); \r
+cosh(x); sinh(x); tanh(x).\r
\r
The constants pi and e are also available. </param>\r
</page>\r
<param name="fofx" type="string" _gui-text="Function">exp(-x*x)</param>\r
<param name="fponum" type="boolean" _gui-text="Calculate first derivative numerically">true</param>\r
<param name="fpofx" type="string" _gui-text="First derivative">x</param>\r
+ <param name="remove" type="boolean" _gui-text="Remove rectangle">true</param>\r
+ <param name="drawaxis" type="boolean" _gui-text="Draw Axes">false</param>\r
<effect>\r
<object-type>rect</object-type>\r
<effects-menu>\r
index d4154dfe7ea1226be17da36b793b9e813ea61314..9948478a1b05df71e9f4fe958a1593da71507aa5 100644 (file)
#!/usr/bin/env python \r
'''\r
+Copyright (C) 2006 Georg Wiora, xorx@quarkbox.de\r
Copyright (C) 2006 Johan Engelen, johan@shouraizou.nl\r
Copyright (C) 2005 Aaron Spike, aaron@ekips.org\r
\r
along with this program; if not, write to the Free Software\r
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
\r
-This program is a modified version of wavy.py by Aaron Spike.\r
+Changes:\r
+ * This program is a modified version of wavy.py by Aaron Spike.\r
+ * 22-Dec-2006: Wiora : Added axis and isotropic scaling\r
\r
'''\r
import inkex, simplepath, simplestyle\r
from math import *\r
from random import *\r
\r
-def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, top, \r
- fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False):\r
+def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bottom, \r
+ fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, isoscale = True, drawaxis = True):\r
\r
if times2pi == True:\r
xstart = 2 * pi * xstart\r
xend = 2 * pi * xend \r
- \r
- # step is the distance between nodes on x\r
- step = (xend - xstart) / (samples-1)\r
- third = step / 3.0\r
- \r
+ \r
# coords and scales based on the source rect\r
scalex = width / (xend - xstart)\r
xoff = left\r
coordx = lambda x: (x - xstart) * scalex + xoff #convert x-value to coordinate\r
scaley = height / (ytop - ybottom)\r
- yoff = top\r
- coordy = lambda y: (ytop-y) * scaley + yoff #convert y-value to coordinate\r
+ yoff = bottom\r
+ coordy = lambda y: (ybottom - y) * scaley + yoff #convert y-value to coordinate\r
+ \r
+ # Check for isotropic scaling and use smaller of the two scales, correct ranges\r
+ if isoscale:\r
+ if scaley<scalex:\r
+ # compute zero location\r
+ xzero = coordx(0)\r
+ # set scale\r
+ scalex = scaley\r
+ # correct x-offset\r
+ xstart = (left-xzero)/scalex\r
+ xend = (left+width-xzero)/scalex\r
+ else :\r
+ # compute zero location\r
+ yzero = coordy(0)\r
+ # set scale\r
+ scaley = scalex\r
+ # correct x-offset\r
+ ybottom = (yzero-bottom)/scaley\r
+ ytop = (bottom+height-yzero)/scaley\r
\r
# functions specified by the user\r
if fx != "":\r
if fpx != "":\r
fp = eval('lambda x: ' + fpx)\r
\r
+ # step is the distance between nodes on x\r
+ step = (xend - xstart) / (samples-1)\r
+ third = step / 3.0\r
+\r
+ a = [] # path array \r
+ # add axis\r
+ if drawaxis :\r
+ # check for visibility of x-axis\r
+ if ybottom<=0 and ytop>=0:\r
+ # xaxis\r
+ a.append(['M ',[left, coordy(0)]])\r
+ a.append([' l ',[width, 0]])\r
+ # check for visibility of y-axis\r
+ if xstart<=0 and xend>=0:\r
+ # xaxis\r
+ a.append([' M ',[coordx(0),bottom]])\r
+ a.append([' l ',[0, -height]])\r
+\r
# initialize function and derivative for 0;\r
# they are carried over from one iteration to the next, to avoid extra function calculations \r
y0 = f(xstart) \r
else: # derivative given by the user\r
d0 = fp(xstart)\r
\r
- a = [] # path array \r
- a.append(['M',[coordx(xstart), coordy(y0)]]) # initial moveto\r
+ # Start curve\r
+ a.append([' M ',[coordx(xstart), coordy(y0)]]) # initial moveto\r
\r
for i in range(int(samples-1)):\r
x = (i+1) * step + xstart\r
else: # derivative given by the user\r
d1 = fp(x)\r
# create curve\r
- a.append(['C',[coordx(x - step + third), coordy(y0 + (d0 * third)), \r
+ a.append([' C ',[coordx(x - step + third), coordy(y0 + (d0 * third)), \r
coordx(x - third), coordy(y1 - (d1 * third)),\r
coordx(x), coordy(y1)]])\r
y0 = y1 # next segment's y0 is this segment's y1\r
action="store", type="string", \r
dest="fpofx", default="cos(x)",\r
help="f'(x) for plotting") \r
+ self.OptionParser.add_option("--remove",\r
+ action="store", type="inkbool", \r
+ dest="remove", default=True,\r
+ help="If True, source rectangle is removed") \r
+ self.OptionParser.add_option("--isoscale",\r
+ action="store", type="inkbool", \r
+ dest="isoscale", default=True,\r
+ help="If True, isotropic scaling is used") \r
+ self.OptionParser.add_option("--drawaxis",\r
+ action="store", type="inkbool", \r
+ dest="drawaxis", default=True,\r
+ help="If True, axis are drawn") \r
self.OptionParser.add_option("--tab",\r
action="store", type="string", \r
dest="tab", default="sampling",\r
except AttributeError:\r
pass\r
\r
+ # top and bottom where exchanhged\r
newpath.setAttribute('d', simplepath.formatPath(\r
drawfunction(self.options.xstart,\r
self.options.xend,\r
self.options.ybottom,\r
self.options.ytop,\r
self.options.samples, \r
- w,h,x,y,\r
+ w,h,x,y+h,\r
self.options.fofx, \r
self.options.fpofx,\r
self.options.fponum,\r
- self.options.times2pi)))\r
+ self.options.times2pi,\r
+ self.options.isoscale,\r
+ self.options.drawaxis)))\r
newpath.setAttribute('title', self.options.fofx)\r
\r
#newpath.setAttribute('desc', '!func;' + self.options.fofx + ';' \r
\r
# add path into SVG structure\r
node.parentNode.appendChild(newpath)\r
- # TODO: make an option wether to remove the rectangle or not.\r
- node.parentNode.removeChild(node)\r
+ # option wether to remove the rectangle or not.\r
+ if self.options.remove:\r
+ node.parentNode.removeChild(node)\r
\r
e = FuncPlot()\r
-e.affect()
\ No newline at end of file
+e.affect()\r