'02 By Axel Nordin 'Input functions in y1 - y8 'Define size of window by setting XMax, XMin, YMax, YMin 'To get a smoother graph set Detail to a higher value 'To get a dotted graph set Lined to 0 sw = screen width sh = screen height cls resize console 0, 0, sw, sh XMin = -10 YMin = -10 XMax = 10 YMax = 10 Detail = 10 Lined = 1 def fn y1( x ) = x def fn y2( x ) = x^2 def fn y3( x ) = -x^2 def fn y4( x ) = -x def fn y5( x ) = 1/x^2 def fn y6( x ) = -1/x^2 def fn y7( x ) = 1/sqr(1+x^2) def fn y8( x ) = -1/sqr(1+x^2) gosub Init for nf = 1 to 8 gosub DrawGraph next end Init: Detail = 1/Detail XScl = sw/(XMax - XMin)'Scale = pixels/graph unit YScl = sh/(YMax - YMin) OriX = (sw-(Xmax - 0 )*XScl)'find the origo by setting x,y = 0 OriY = sh-(sh-(YMax - 0)*YScl)' The screen pos is found by finding the distance between the point and the XYMax and the converting it into screen coordinates Line OriX, 0, OriX, sh Line 0, OriY, sw, OriY return DrawGraph: XD = XMin : gosub GetfXD moveto (sw-(Xmax - XMin )*XScl), sh-(sh-(YMax - fY )*YScl) forecolor 35535, 65535, 0 for x = XMin to XMax Step Detail Xs = (sw-(Xmax - x)*XScl)'Get the screen coordinates XD = x : gosub GetfXD Ys = sh-(sh-(YMax - fY )*YScl) if Lined = 1 then lineto Xs, Ys moveto Xs, Ys else plot Xs, Ys end if next return GetfXD: select case nf case 1: fY = fn y1( XD ) case 2: fY = fn y2( XD ) case 3: fY = fn y3( XD ) case 4: fY = fn y4( XD ) case 5: fY = fn y5( XD ) case 6: fY = fn y6( XD ) case 7: fY = fn y7( XD ) case 8: fY = fn y8( XD ) end select return