|
发表于 2013-6-27 21:09:59
|
显示全部楼层
- var func= "sin(x)+cos(y)"
- var x_min=-6.3,x_max=6.3,y_min=-3.1,y_max=3.1,sp=0.5
- var px1=0, py1=0, px2=0, py2=0
- var bx, by, g=30, h=30
- var cos_s, sin_s, cos_t, sin_t
- var dx,dy
- ::main()
- var i
- var func2
- while 1>0
- i = show_menu()
- if i==2
- func2 = requeststr("sin(x)+cos(y)","f(x,y)=")
- if dim(func2) then
- func=func2
- ifend
- continue
- ifend
- if i==1 then
- view()
- continue
- ifend
- if i==3 then
- exit()
- ifend
- wend
- ::endf
- ::show_menu()
- var index;
- index=menu("3D Function Power","1: Draw ","2: z(x,y) ","3: Exit ")
- return index
- ::endf
- ::view()
- var key
- # 30020 = left
- # 30021 = right
- while 1
- draw_3d()
- key = getkey()
- if key==30018 or key==30020 # up
- h = h + 10
- continue
- ifend
- if key==30023 or key==30021 # down
- h = h -10
- continue
- ifend
- if key==30002
- ClrIO()
- return nil
- ifend
- wend
- ::endf
- ::rcl_deg()
- var s,t
- s = 3.1415926 * g / 180;
- t = 3.1415926 * (90 - h) / 180;
- sin_s = sin(s)
- cos_s = cos(s)
- sin_t = sin(t)
- cos_t = cos(t)
- ::endf
- ::_3d_to_win(x,y,z)
- var w
- if g !=0
- w = x * cos_s - y * sin_s
- y = x * sin_s + y * cos_s
- x = w
- ifend
- if h != 90 then
- w = y * cos_t - z * sin_t;
- z = y * sin_t + z * cos_t;
- y = w;
- IfEnd
- px2 = px1
- py2 = py1
- px1 = (x - x_min)*(127/(x_max-x_min))+1
- py1 = (y - y_min)*(63 /(y_max-y_min))+1
- ::EndF
- ::draw_3d()
- var x,y,z
- rcl_deg()
- clrio()
- x = x_min
- while 1
- if x > x_max
- break
- ifend
- y = y_min
- z = eval(func)
- _3d_to_win(x,y,z)
- while y <= y_max
- z = eval(func)
- _3d_to_win(x,y,z)
- line(px1,py1,px2,py2)
- y = y+sp
- wend
- putdisp()
- x = x+sp
- Wend
- y = y_min
- while y <= y_max
- x = x_min
- z = eval(func)
- _3d_to_win(x,y,z)
- while x <= x_max
- z = eval(func)
- _3d_to_win(x,y,z)
- line(px1,py1,px2,py2)
- x = x+sp
- wend
- putdisp()
- y = y+sp
- wend
- locate(1,1,func)
- ::endf
复制代码 |
|