Hi all,
I am a complete newbie to VPython, but I got hooked. I
tried the bouncing ball, enriched it with audio from
Pygame, and the simple function plot; so little code,
so great
effects!
My first problem: how do I draw a line from x to y? I
know how to plot functions with VPython, such as
x = f(x), see above
but how do I plot a 2D function such as
x = f1(x)
y = f2(y)
draw line between x and y?
In Python it is done, e.g., like this
while theta < 75.39:
r = math.exp(math.cos(theta))-
2*math.cos(4*theta)+(math.sin(theta/12))**5
# convert from polar coordinates
x = r*math.cos(theta)
y = r*math.sin(theta)
# scale to canvas size
xx = (x*30) + 150
yy = (y*30) + 150
if (theta == 0.0):
Canvas.Line(self.canvas, xx, yy, xx, yy)
else:
Canvas.Line(self.canvas, xOld, yOld, xx, yy)
self.canvas.update_idletasks()
xOld = xx
yOld = yy
theta = theta + 0.02
which, in this case, creates a butterfly curve
(from http://www.pythonmania.de/article/pybutt.html)
Unfortunately, browsing tutorials and documents on
www.vpython.org, I could not find a "line " command.
If there would be one, 3D "butterfly" curves
would be possible, too.
Thanks,
siggi
____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.
|