A small function plotter in MMBasic

' a function plotting program. + and - zoom in and out. Esc exits the program.
' still work in progress. I'm keeping the code short so not to create errors in editor.
CLS RGB(white)
rd=RGB(red)
bl=RGB(blue)
gy=RGB(gray)
wh=RGB(white)
'define constants
gs=10 'grid steps
oX=160 'x of origin
oY=160 'y of origin
'sc=0.1 'original scaling
'set up display with a white background
Color bl, RGB(white)
'ask the user for a function expression
Print "Function:"
Input funcExpression$
Print "Scaling:"
Input scale$
sc=Val(scale$)
'main loop
'draw the grid
Do
For x=0 To 320 Step gs
Line x, 0, x, 319, , gy
Next x
For y=0 To 320 Step gs
Line 0, y, 319, y, , gy
Next y
'draw x and y axes
Line oX, 0, oX, 319, 2, rd
Line 0, oY, 319, oY, 2, rd
For x=-160 To 159
'evaluate the function for x
y=Eval(funcExpression$)*sc
'scale down the y to fit the screen
nY=oY-y
Line oX+x, nY, oX+x+1, nY, 4, bl
Next x
'second loop
Do
'check for key press
key$=Inkey$
If key$="+" Then
sc=sc*0.9
CLS wh
Exit Do 'exit second loop
ElseIf key$="-" Then
sc=sc*1.1
CLS wh
Exit Do 'exit second loop
End If
'exit the first loop if ESC is pressed
If key$=Chr$(27) Then
Exit Do
End If
Loop
Pause 100
'exit the first loop if ESC is pressed
If key$=Chr$(27) Then
Exit Do
End If
Loop
'restore screen to original
CLS RGB(black), RGB(green)
3 Likes

Thanks for posting that. I love it when people post their code as it allows everybody to see other ideas in different ways of thinking.

Being a long time since I programmed in basic and that was on an HP 71B and a few sharp and Casio calculators.

2 Likes