''' Curves(sin(x), circle, abs,cuspidal cubic, cycloid) Programmed by Ching-Shoei Chiang ''' from math import * from visual import * #from visual.text import * # http://linuxgazette.net/144/john.html scene.width = 2.5 * scene.height #1 draw 3 axis. xaxis = arrow(pos=(0,0), axis=(1,0), shaftwidth=0.01, color=color.red) yaxis = arrow(pos=(0,0), axis=(0,1), shaftwidth=0.01, color=color.green) # Work only for capital letters. It will print * for other letters #xtex = label(pos=(1,0), text='X', xoffset = 3, box=false, line=false, color=color.red, height=0.08, width=0.08, justify='center') #ytex = label(pos=(0,1), text='Y', yoffset = 3, box=false, line=false, color=color.green, height=0.06, width=0.06, justify='center') # Curve in 2D #1 繪製一個方形 #square = curve(pos = [(0,0), (0,1), (1,1), (1,0), (0,0)], radius=0.01) #2 繪製點(非曲線),並設定不同的粗筆,繪製一個方形的四的端點 #square = points(pos = [(0,0), (0,1), (1,1), (1,0), (0,0)], radius=0.05, color=color.white) #3 函數 #eqn = "sin(x)" #x = arange(0, 6.28+0.1, 0.1) #curve( x=x, y=eval(eqn) ) #4 參數式 x(t)=cos(t), y(t)=sin(t) #t=arange(0,2*pi+0.1, 0.1) #curve(x=cos(t), y=sin(t), red=cos(t), green=sin(t), blue=0.2, radius=0.03) #5 參數式 x(t)=t, y(t)=|t| and 函數(y = |x|) #t = arange(-1,1.1,0.1) #curve(x=t, y=abs(t)) #6 參數式x(t)=t**2, y(t)=t**3, t in R #test different value of maxno, and step #step = 0.01 #maxno = 3 #t=arange(-maxno, maxno+step, step) #curve(x=t**2, y=t**3, radius=0.05) #7 參數式 x(t)=t**3-4*t, y(t)=t**2-4, t in R # Do it by student. Is this function a 1-1 function? #8 # Cycloid. 此指令需要在未畫軸線之前,讓scene.width = 2.5 * scene.height指令可執行 # t[0]==0 is the first drawing point for the circle #t=arange(0,2*pi+0.1, 0.1) #curve(pos=[(-1,0),(2*pi+1,0)], color=color.blue) #L=curve(color=color.yellow) #for deltat in arange(0, 2*pi+0.1, 0.1): # curve(x=deltat-sin(t+deltat), y=1-cos(t+deltat), red=t/(2*pi), green=t/(2*pi), blue=t/(2*pi), radius=0.01) #curve(x=t-sin(t), y=1-cos(t), color=color.green) #9 Tractrix (方法同#5) t = arange(0.1,pi,0.1) curve(x=cos(t)+log(tan(t/2)), y=sin(t))