Traduction pour la NUMWORKS d’un programme BASIC trouvé p.41 dans le livre “Mathématiques et graphismes” (1985 - Edition PSI) à consulter ici.
from turtle import * from math import * from kandinsky import fill_rect from time import sleep speed(0) pencolor(255,255,0) def ex0(): def g(t): return cos(t),sin(t),1/t return g,-2,2,-1,.5,-10,10 def ex1(): def g(t): return 2-t*t,-2*t,t**3 return g,-5,5,-2,1.5,-3,3 def ex2(): def g(t): return cos(3*t),sin(3*t),sin(t)**2 return g,-1,1,-1.1,1.1,0,2*pi def ex3(): def g(t): return cos(3*t),sin(3*t),cos(t) return g,-1.2,0.8,-1.2,1.2,-pi/2,pi/2 def ex4(): def g(t): return cos(t),sin(t),-1-int(t/2/pi) return g,-6,6,-6,6,0,10*pi def ex5(): def g(t): return cos(t),sin(t),t*t*sin(t) return g,-4,4,-10,3,-pi,pi def ex6(): def g(t): return cos(t), sin(t),(1-t*t)/(1+t*t) return g,-1.5,1.5,-1.5,1.5,-2*pi,2*pi def ex7(): def g(t): return cos(t),sin(t),t/(1+t) return g,-3,3,-3,3,-10,10 def ex8(): def g(t): return cos(t),sin(t),sqrt(abs(t)) return g,-4,4,-4,4,-10,10 def ex9(): def g(t): return cos(t),sin(t),exp(-exp(-t/5)) return g,-2,2,-2,3,-5,10 def tracer(x,y): global f, pts if x<xi or x>xs or y<yi or y>ys: return f += 1 pts[f] = [-160 + ceil(320 * (x-xi)/(xs-xi)),-111 + ceil(222 * (y-yi)/(ys-yi))] if f == 1 and pts[0] == pts[1]: f = -1 elif f == 1: penup() goto(pts[0]) pendown() goto(pts[1]) hideturtle() for k in range(10): fill_rect(0,0,320,222,(0,0,0)) g,xi,xs,yi,ys,ti,ts = eval('ex'+str(k)+'()') pts = [[0,0],[0,0]] n = 100 th = (ts-ti) / (n-1) for i in range(n): try:a, b, c = g(ti + i * th) except:continue f = -1 if b!=0: tracer(xi,-(c+a*xi)/b) tracer(xs,-(c+a*xs)/b) if a!=0: tracer(-(c+b*yi)/a,yi) tracer(-(c+b*ys)/a,ys) sleep(1)