# parametric plot .bas # with auto-scaling grid # version 1.3 new t$="parametric plot" pi=atn(1)*4 : e=exp(1) zmin = 0 : zmax = 100 : zstep = 2 # put default equations here x$="10*sin(z/8) " y$="4*cos(pi/3+z/16) " y2$="x/3" # looptop: draw -1 draw 0,15,160,145,-7 for i=0 to 6: s$(i)="": next i form btn 70,120,40,10,"Plot",1 form fld 70,20,44,12,str$(zmin),1 form fld 70,32,44,12,str$(zmax),1 form fld 70,44,44,12,str$(zstep),1 form fld 70,68,84,12,x$,1 form fld 70,80,84,12,y$,1 form fld 70,92,84,12,y2$,1 draw "z min",20,20 draw "z max",20,32 draw "z step",20,44 draw "x:fn(z)",20,68 draw "y:fn(z)",20,80 draw "w:fn(z)",20,92 c=asc(input$(1)) # wait for imput form reset 0,0,0,0,t$,-1 :' clear it # get parameters zmin = val(s$(0)) zmax = val(s$(1)) zstep = val(s$(2)) x$=s$(3) y$=s$(4) : y2$=s$(5) # calculate draw "calculating",40,76 n=1+int((zmax-zmin)/zstep) dim x(n),y(n),y2(n) z=zmin for i=0 to n-1 x = eval(x$) : x(i) = x y = eval(y$) : y(i) = y : y2(i)=y if y2$<>"" then y2(i)=eval(y2$) z = z + zstep next i gosub plot(n) # find tap location while 1 x = fn pen(0) y = fn pen(2) if (y > 150) then goto looptop: x=round((x-x0)/xs,1) y=round(-(y-y0)/ys,1) p$=" " & str$(x) & ", " p$=p$ & str$(y) & " " draw p$,50,150 wend end # subroutines 3000 rem #plot(n) subroutine sub plot(nxy, i,j,k,ymax,ymin, s,yad,xmax,xmin,ya0,ya1) draw -1 : rem clear display draw 0,14,160,146,-7 ymin = y(0) : ymax = y(0) xmin = x(0) : xmax = x(nxy-1) for i = 1 to nxy-1 if x(i) < xmin then xmin = x(i) if x(i) > xmax then xmax = x(i) if y(i) < ymin then ymin = y(i) if y(i) > ymax then ymax = y(i) if y2(i) < ymin then ymin = y2(i) if y2(i) >ymax then ymax=y2(i) next i if ymin-ymax = 0 then ymax = 1.1*ymin rem ** calc y grid ** call grid(nxy,ymin,ymax) :' ->uad if ua0 < ymin then ymin = ua0 if ua1 > ymax then ymax = ua1 yad = uad rem scale s = 128 x0 = 2 y0 = 16+s ys = s/(ymax-ymin) y0 = y0+ys*ymin draw color 0,0x33,0x99,1 y=ymin while y < ymax i = y0-y*ys draw 2,i,2+s,i,2 y = y+uad wend rem ** x axis ** grid(nxy,xmin,xmax) : rem uad if ua0 < xmin then xmin = ua0 if ua1 > xmax then xmax = ua1 xad = uad rem scale xs = s/(xmax-xmin) x0 = 2-xs*xmin x=xmin while x < xmax i = x0+x*xs draw i,16,i,16+abs(s),2 x = x+xad wend draw color 0x33,0x33,0x33,1 draw 2,16,s,s,4 draw str$(ymin),133,7+s draw str$(ymax),133,14 draw str$(xmin),2,18+s draw str$(xmax),s-4,18+s rem ** graph the data ** draw color 0xFF,0,0,1 : rem red moveto x0+xs*x(0),y0-ys*y(0) for i = 1 to nxy-1 lineto x0+xs*x(i),y0-ys*y(i) next i if (y2$<>"") draw color 0,0x99,0,1 : rem green moveto x0+xs*x(0),y0-ys*y2(0) for i = 1 to nxy-1 lineto x0+xs*x(i),y0-ys*y2(i) next i endif end sub #grid size subroutine #grid ( nxy, umin, umax ) -> ua0,uad sub grid(nxy, umin,umax, u,v,i,a1,fm, na1,m) u = abs(umax-umin)/8 a1 = log(u)/log(10) na1 = int(a1+0.49) if u < 1 then na1 = na1-1 v = u/(10^na1) uad = 10^na1 if v > sqr(2) then uad = 2*(10^na1) if v > sqr(5) then uad = 5*(10^na1) if v > sqr(10) then uad = 10*(10^na1) # if uad < (umax-umin)/nxy then uad = (umax-umin)/nxy m = int(umin/uad) if umin < 0 then m = m-1 ua0 = uad*m m = int(umax/uad)+1 ua1 = uad*m if ya1 < umax then ya1 = umax end sub end run