option explicit
declare sub plotArray( byval addr as single ptr, byval siz as integer, byval xscale as integer, byval yscale as integer, byval col as integer )
type fp as function ( byval x as single ) as single
declare function makeArray( byval f as fp ) as single ptr
declare sub plotFunc( byval f as fp, byval xscale as integer, byval yscale as integer, byval col as integer )
declare function square( byval x as single ) as single
declare function linear( byval x as single ) as single
screen 13
plotFunc(@linear, 20, 20, 12)
sleep
end
sub plotArray( byval addr as single ptr, byval siz as integer, byval xscale as integer, byval yscale as integer, byval col as integer )
for i as integer = 0 to 199
pset (0, i*yscale), col
next i
for i = 0 to 319
pset (i*xscale, 199), col
next i
for i = 0 to siz
line (i*xscale, cint(199-(*(addr + i))*yscale))-((i+1)*xscale, cint(200-(*(addr + i + 1))*yscale)), col
next i
end sub
function makeArray( byval f as fp ) as single ptr
dim arr(319) as single
for i as integer = 0 to ubound(arr)
arr(i) = f(i)
next i
makeArray = @arr(0)
end function
sub plotFunc( byval f as fp, byval xscale as integer, byval yscale as integer, byval col as integer )
plotArray(makeArray(f), 319, xscale, yscale, col)
end sub
4
function square( byval x as single ) as single
square = x^2
end function
function linear( byval x as single ) as single
linear = x
end function