From: johanengelen Date: Thu, 28 Dec 2006 14:27:30 +0000 (+0000) Subject: Committed [ 1620672 ] Funcplot: New features and bug fixes. With some adjustments. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f7b7ce562088ac6b9eff7a3ce00c683e842fa5d0;p=inkscape.git Committed [ 1620672 ] Funcplot: New features and bug fixes. With some adjustments. --- diff --git a/share/extensions/funcplot.inx b/share/extensions/funcplot.inx index 5c9ba6230..6a6d740d1 100644 --- a/share/extensions/funcplot.inx +++ b/share/extensions/funcplot.inx @@ -4,18 +4,23 @@ funcplot.py inkex.py - + 0.0 1.0 false 0.0 1.0 8 + false The following functions are available: (the available functions are the standard python math functions) -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). +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); hypot(x,y); +cos(x); sin(x); tan(x); degrees(x); radians(x); +cosh(x); sinh(x); tanh(x). The constants pi and e are also available. @@ -23,6 +28,8 @@ The constants pi and e are also available. exp(-x*x) true x + true + false rect diff --git a/share/extensions/funcplot.py b/share/extensions/funcplot.py index d4154dfe7..9948478a1 100644 --- a/share/extensions/funcplot.py +++ b/share/extensions/funcplot.py @@ -1,5 +1,6 @@ #!/usr/bin/env python ''' +Copyright (C) 2006 Georg Wiora, xorx@quarkbox.de Copyright (C) 2006 Johan Engelen, johan@shouraizou.nl Copyright (C) 2005 Aaron Spike, aaron@ekips.org @@ -17,31 +18,48 @@ 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 -This program is a modified version of wavy.py by Aaron Spike. +Changes: + * This program is a modified version of wavy.py by Aaron Spike. + * 22-Dec-2006: Wiora : Added axis and isotropic scaling ''' import inkex, simplepath, simplestyle from math import * from random import * -def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, top, - fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False): +def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bottom, + fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, isoscale = True, drawaxis = True): if times2pi == True: xstart = 2 * pi * xstart xend = 2 * pi * xend - - # step is the distance between nodes on x - step = (xend - xstart) / (samples-1) - third = step / 3.0 - + # coords and scales based on the source rect scalex = width / (xend - xstart) xoff = left coordx = lambda x: (x - xstart) * scalex + xoff #convert x-value to coordinate scaley = height / (ytop - ybottom) - yoff = top - coordy = lambda y: (ytop-y) * scaley + yoff #convert y-value to coordinate + yoff = bottom + coordy = lambda y: (ybottom - y) * scaley + yoff #convert y-value to coordinate + + # Check for isotropic scaling and use smaller of the two scales, correct ranges + if isoscale: + if scaley=0: + # xaxis + a.append(['M ',[left, coordy(0)]]) + a.append([' l ',[width, 0]]) + # check for visibility of y-axis + if xstart<=0 and xend>=0: + # xaxis + a.append([' M ',[coordx(0),bottom]]) + a.append([' l ',[0, -height]]) + # initialize function and derivative for 0; # they are carried over from one iteration to the next, to avoid extra function calculations y0 = f(xstart) @@ -57,8 +93,8 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, top, else: # derivative given by the user d0 = fp(xstart) - a = [] # path array - a.append(['M',[coordx(xstart), coordy(y0)]]) # initial moveto + # Start curve + a.append([' M ',[coordx(xstart), coordy(y0)]]) # initial moveto for i in range(int(samples-1)): x = (i+1) * step + xstart @@ -68,7 +104,7 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, top, else: # derivative given by the user d1 = fp(x) # create curve - a.append(['C',[coordx(x - step + third), coordy(y0 + (d0 * third)), + a.append([' C ',[coordx(x - step + third), coordy(y0 + (d0 * third)), coordx(x - third), coordy(y1 - (d1 * third)), coordx(x), coordy(y1)]]) y0 = y1 # next segment's y0 is this segment's y1 @@ -115,6 +151,18 @@ class FuncPlot(inkex.Effect): action="store", type="string", dest="fpofx", default="cos(x)", help="f'(x) for plotting") + self.OptionParser.add_option("--remove", + action="store", type="inkbool", + dest="remove", default=True, + help="If True, source rectangle is removed") + self.OptionParser.add_option("--isoscale", + action="store", type="inkbool", + dest="isoscale", default=True, + help="If True, isotropic scaling is used") + self.OptionParser.add_option("--drawaxis", + action="store", type="inkbool", + dest="drawaxis", default=True, + help="If True, axis are drawn") self.OptionParser.add_option("--tab", action="store", type="string", dest="tab", default="sampling", @@ -143,17 +191,20 @@ class FuncPlot(inkex.Effect): except AttributeError: pass + # top and bottom where exchanhged newpath.setAttribute('d', simplepath.formatPath( drawfunction(self.options.xstart, self.options.xend, self.options.ybottom, self.options.ytop, self.options.samples, - w,h,x,y, + w,h,x,y+h, self.options.fofx, self.options.fpofx, self.options.fponum, - self.options.times2pi))) + self.options.times2pi, + self.options.isoscale, + self.options.drawaxis))) newpath.setAttribute('title', self.options.fofx) #newpath.setAttribute('desc', '!func;' + self.options.fofx + ';' @@ -165,8 +216,9 @@ class FuncPlot(inkex.Effect): # add path into SVG structure node.parentNode.appendChild(newpath) - # TODO: make an option wether to remove the rectangle or not. - node.parentNode.removeChild(node) + # option wether to remove the rectangle or not. + if self.options.remove: + node.parentNode.removeChild(node) e = FuncPlot() -e.affect() \ No newline at end of file +e.affect()