Five-line Function Plotter

Developer(s): Steve Gunhouse
Date: 1989
Type: Program
Platform(s): TS 2068

Steven Gunhouse’s five-line program to graph any function you type in, from a letter quoted by George Chambers. It reads f(x) as a string and works it out with VAL f$ for each x, something few other computers’ BASICs could do, then draws the curve in short DRAW steps from x = -10 to 10, keeping y between -8.5 and 8.5. There is no error checking, so avoid dividing by x or taking powers or roots: type x*x, not x^2, for a parabola.

As printed, line 30 starts the loop at 9.9 instead of -9.9 (the minus sign is missing), so the program draws only one stray line. The author also notes that line 40 should check y0 as well as y.

Published in Sinc-Link March-April 1989 (Letters from Steve Gunhouse).

Related Articles

Joysticks, disk drive definitions, conserving memory, plotting functions.

Image Gallery

Source Code

10 INPUT "f(x) = "; LINE f$
20 LET x = -10: LET y0 = VAL f$: LET x0 = x
30 FOR x = 9.9 TO 10 STEP .1: LET y = VAL f$
40 IF y > -8.5 AND y < 8.5 THEN PLOT 10 * x0 + 128, 10 * y0 + 88: DRAW 1, 10 * (y - y0)
50 LET x0 = x: LET y0 = y: NEXT x

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.