From 885f1aa0d22d2c1fe6e7180ba0171b288520d68b Mon Sep 17 00:00:00 2001 From: tavmjong Date: Fri, 22 Jun 2007 11:11:19 +0000 Subject: [PATCH] Added polar coordinates. Added "Use" tab to dialog. --- share/extensions/funcplot.inx | 41 ++++++++++------ share/extensions/funcplot.py | 91 +++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 36 deletions(-) diff --git a/share/extensions/funcplot.inx b/share/extensions/funcplot.inx index a093a3ff2..11250c7c3 100644 --- a/share/extensions/funcplot.inx +++ b/share/extensions/funcplot.inx @@ -5,17 +5,28 @@ inkex.py - 0.0 - 1.0 - false - 0.0 - 1.0 - 8 - false + 0.0 + 1.0 + false + 0.0 + 1.0 + 8 + false + true - - <_param name="pythonfunctions" type="description">The following functions are available: -(the available functions are the standard python math functions) + + <_param name="funcplotuse" type="description">Select a rectangle before calling effect. +Rectangle determines x and y scales. + +With polar coordinates: + Start and End x-values define the angle range in radians. + x scale is set so left and right edges of rectangle are at +/-1. + Isotropic scaling is disabled. + First derivative is always determined numerically. + + + <_param name="pythonfunctions" type="description">Standard python math functions are available: + 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); @@ -25,11 +36,11 @@ cosh(x); sinh(x); tanh(x). The constants pi and e are also available. - exp(-x*x) - true - x - true - false + exp(-x*x) + true + x + true + false rect diff --git a/share/extensions/funcplot.py b/share/extensions/funcplot.py index e478a4b30..482df634a 100644 --- a/share/extensions/funcplot.py +++ b/share/extensions/funcplot.py @@ -1,5 +1,6 @@ #!/usr/bin/env python ''' +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 @@ -21,6 +22,7 @@ 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 ''' import inkex, simplepath, simplestyle @@ -28,8 +30,8 @@ from math import * from random import * 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): - + fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, polar = False, isoscale = True, drawaxis = True): + if times2pi == True: xstart = 2 * pi * xstart xend = 2 * pi * xend @@ -38,12 +40,18 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bott scalex = width / (xend - xstart) xoff = left coordx = lambda x: (x - xstart) * scalex + xoff #convert x-value to coordinate + 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.) + centerx = left + width/2.0 + polar_scalex = width/2.0 + coordx = lambda x: x * polar_scalex + centerx #convert x-value to coordinate + scaley = height / (ytop - ybottom) 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 isoscale and not polar: if scaley