funcplot.py revision af18e4d740a0efe3434ee1e7559fa7a099f9d39e
'''
Copyright (C) 2007 Tavmjong Bah, tavmjong@free.fr
Copyright (C) 2006 Georg Wiora, xorx@quarkbox.de
Copyright (C) 2006 Johan Engelen, johan@shouraizou.nl
Copyright (C) 2005 Aaron Spike, aaron@ekips.org
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
Changes:
* This program is a modified version of wavy.py by Aaron Spike.
* 22-Dec-2006: Wiora : Added axis and isotropic scaling
* 21-Jun-2007: Tavmjong: Added polar coordinates
'''
# standard library
from math import *
from random import *
# local library
import inkex
import simplepath
import simplestyle
fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, polar = False, isoscale = True, drawaxis = True, endpts = False):
# coords and scales based on the source rect
return []
if polar : # Set scale so that left side of rectangle is -1, right side is +1.
# (We can't use xscale for both range and scale.)
inkex.errormsg(_("y-interval cannot be zero. Please modify 'Y value of rectangle's top' or 'Y value of rectangle's bottom'"))
return []
# Check for isotropic scaling and use smaller of the two scales, correct ranges
# compute zero location
# set scale
# correct x-offset
else :
# compute zero location
# set scale
# correct x-offset
# functions specified by the user
try:
if fx != "":
if fpx != "":
# handle incomplete/invalid function gracefully
except SyntaxError:
return []
# step is the distance between nodes on x
a = [] # path array
# add axis
if drawaxis :
# check for visibility of x-axis
# xaxis
# check for visibility of y-axis
# xaxis
# initialize function and derivative for 0;
# they are carried over from one iteration to the next, to avoid extra function calculations.
if polar :
if polar :
else: # derivative given by the user
# Start curve
if endpts:
else:
if polar :
else: # derivative given by the user
# create curve
a.append([' C ',
])
if endpts:
return a
help="Start x-value")
help="End x-value")
help="Multiply x-range by 2*pi")
help="Plot using polar coordinates")
help="y-value of rectangle's bottom")
help="y-value of rectangle's top")
help="Samples")
help="f(x) for plotting")
help="Calculate the first derivative numerically")
help="f'(x) for plotting")
help="If True, clip with copy of source rectangle")
help="If True, source rectangle is removed")
help="If True, isotropic scaling is used")
help="If True, axis are drawn")
help="If True, end points are added")
help="The selected UI-tab when OK was pressed")
help="dummy")
help="dummy")
newpath = None
# create new path with basic dimensions of selected rectangle
#copy attributes of rect
if s:
if t:
# top and bottom were exchanged
w,h,x,y+h,
#newpath.setAttribute('desc', '!func;' + self.options.fofx + ';'
# + self.options.fpofx + ';'
# + `self.options.fponum` + ';'
# + `self.options.xstart` + ';'
# + `self.options.xend` + ';'
# + `self.options.samples`)
# add path into SVG structure
# option whether to clip the path with rect or not.
if defs == None:
# option wether to remove the rectangle or not.
if newpath is None:
if __name__ == '__main__':
e = FuncPlot()
e.affect()
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99