kirby urner schrieb:
Hi Brian,
....
This ran perfectly on Python 3.1rc1 (r31rc1:73069, May 31 2009,
08:57:10) on my WinXP box (one of a few).
Note: if this level of chaos / noise bothers you (the functions are
algebraically the same, after all), then I recommend using the decimal
type instead of the floating type, converting to float just to make
your turtle happy:
That's fine (for the turtle). But if someone thinks that everything is
calculated
"correctly" now, she/he is bound to get disappointed. And that's the
point (imho).
Regards,
Gregor
# Author: Gregor Lingl
# amended to use Decimal by Kirby Urner 2009-09-28
# re-corrupted to show the vainness (in principle) of kirby's effort
2009-09-28
# Date: 2009-06-24
# A demonstration of chaos
from turtle import *
from decimal import Decimal
k = Decimal('3.9')
N = 160
def f(x):
x = Decimal(str(x))
return k*x*(1-x)
def g(x):
x = Decimal(str(x))
return k*(x-x**2)
def h(x):
x = Decimal(str(x))
return k*x-k*x*x
def jumpto(x, y):
penup(); goto(x,y)
def line(x1, y1, x2, y2):
jumpto(x1, y1)
pendown()
goto(x2, y2)
def coosys():
line(-1, 0, N+1, 0)
line(0, -0.1, 0, 1.1)
def plot(fun, start, colour):
pencolor(colour)
x = start
jumpto(0, x)
pendown()
dot(5)
for i in range(N):
x=fun(x)
goto(i+1,float(x))
dot(5)
def main():
reset()
setworldcoordinates(-1.0,-0.1, N+1, 1.1)
speed(0)
hideturtle()
coosys()
plot(f, 0.35, "blue")
plot(g, 0.35, "green")
plot(h, 0.35, "red")
# Now zoom in:
for s in range(220):
setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
return "Done!"
if __name__ == "__main__":
main()
mainloop()
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig