Here's an example to test it:
You will need IanM's MatrixUtils for creating the subdivided plain.
sync on
sync rate 100
`Constants
#constant MinX -1.0
#constant MinY -1.0
#constant MaxX 1.0
#constant MaxY 1.0
#constant SizeX 50
#constant SizeY 50
#constant CamDist 3.0
#constant CamHeight 3.0
#constant COLOR_Lo 0xFF00FF00
#constant HEIGHT_Lo -2.0
#constant COLOR_Hi 0xFFFF0000
#constant HEIGHT_Hi 2.0
`Pointer to variables!
#constant MemVar 1
make memblock MemVar, 2 * 8
global pVarX as DWORD : pVarX = get memblock ptr(1)
global pVarY as DWORD : pVarY = get memblock ptr(1) + 8
`Set these variables for muParser
muSetVariable "x", pVarX
muSetVariable "y", pVarY
`Make a plain
make object plain 1, MaxX - MinX, MaxY - MinY, SizeX, SizeY, 338
set object wireframe 1, 1
set object cull 1, 0
txt$ = ""
do
`Input of the formula
char$ = entry$()
select asc(char$)
case 13
`Build function mesh
BuildFunctionMesh(txt$)
txt$ = ""
endcase
case 8
txt$ = left$(txt$, len(txt$) - 1)
endcase
case default
txt$ = txt$ + char$
endcase
endselect
clear entry buffer
`Print on screen
ink rgb(255, 255, 255), 0
text 0, 0, "Formula: " + txt$
angle# = wrapvalue(angle# + 0.1)
position camera newxvalue(0.0, angle#, CamDist), CamHeight, newzvalue(0.0, angle#, CamDist)
point camera 0, 0, 0
sync
loop
function BuildFunctionMesh(formula$)
`Update mu
muSetExpression formula$
`Lock vertices
lock vertexdata for limb 1, 0
`Loop through vertices
for i = 0 to get vertexdata vertex count() - 1
`Get position
x# = get vertexdata position x(i)
z# = get vertexdata position z(i)
`Calculate
muWriteDoubleFloat pVarX, x#
muWriteDoubleFloat pVarY, z#
y# = muEvaluate()
`Update object
set vertexdata position i, x#, y#, z#
`Calculate a color
t# = (y# - HEIGHT_Lo)/(HEIGHT_Hi - HEIGHT_Lo)
if t# < 0.0 then t# = 0.0
if t# > 1.0 then t# = 1.0
red = int(rgbr(COLOR_Lo) + (rgbr(COLOR_Hi) - rgbr(COLOR_Lo)) * t#)
green = int(rgbg(COLOR_Lo) + (rgbg(COLOR_Hi) - rgbg(COLOR_Lo)) * t#)
blue = int(rgbb(COLOR_Lo) + (rgbb(COLOR_Hi) - rgbb(COLOR_Lo)) * t#)
set vertexdata diffuse i, rgb(red, green, blue)
next i
unlock vertexdata
endfunction
Cheers!
Sven B