You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
990 B
Plaintext

# graph area
plotx = 50
ploty = 50
plotw = 380
ploth = 220
cx = plotx + plotw / 2
cy = ploty + ploth / 2
# graph range
xmin = 0 - 10
xmax = 10
ymin = 0 - 10
ymax = 10
xinc = plotw / (xmax - xmin)
yinc = ploth / (ymax - ymin)
mlines = color(3, 3, 3)
func(makegrid) {
rect(plotx, ploty, plotw, ploth, 0)
x = plotx
while (x <= plotx + plotw) {
line(x, ploty, x, ploty + ploth, mlines)
x = x + xinc
}
y = ploty
while (y <= ploty + ploth) {
line(plotx, y, plotx + plotw, y, mlines)
y = y + yinc
}
line(cx, ploty, cx, ploty + ploth, 32767)
line(plotx, cy, plotx + plotw, cy, 32767)
}
#
# BIG LOOP - ask for equ, graph it
#
makegrid()
clearcmd = ""
while (1) {
rect(0, 0, 480, 40, 0)
print("f(x) = ")
fx = gets()
if (fx == clearcmd) {
makegrid()
} else {
# do function
X = xmin
while (X < xmax) {
y = solve(fx)
y = 0 - y
if ((y >= ymin) & (y <= ymax)) {
pixel(cx + X * xinc, cy + y * yinc, 511)
}
X = X + 1 / xinc
}
}
ppos(0, 0)
}