'=========================================================================== ' Subject: GRAPHING PROGRAM Date: 12-27-95 (00:13) ' Author: Aaron Scott Zabudsky Code: QB, QBasic, PDS ' Origin: zabudsk@ecf.toronto.edu Packet: ALGOR.ABC '=========================================================================== DECLARE SUB pprint (x!, y!, A$) SCREEN 12 PALETTE 0, 63 + 256 * 63 + 65536 * 63 PALETTE 15, 0 sx = 640 sy = 480 axisc = 12 gridc = 9 autounits = 1 xunitovr = .2 yunitovr = .2 xmin = -5 xmax = 5 ymin = -5 ymax = 5 IF xmin <= 0 AND xmax >= 0 THEN LINE (((0 - xmin) / (xmax - xmin)) * sx - 1, 0)-(((0 - xmin) / (xmax - xmin)) * sx + 1, sy), axisc, BF END IF IF ymin <= 0 AND ymax >= 0 THEN LINE (0, sy - ((0 - ymin) / (ymax - ymin)) * sy - 1)-(sx, sy - ((0 - ymin) / (ymax - ymin)) * sy + 1), axisc, BF END IF IF autounits = 1 THEN xunitovr = (xmax - xmin) / 10 yunitovr = (ymax - ymin) / 10 rx = 0 ry = 0 IF xunitovr < 1 THEN WHILE xunitovr < 1 xunitovr = xunitovr * 10 rx = rx - 1 WEND END IF IF xunitovr >= 10 THEN WHILE xunitovr >= 10 xunitovr = xunitovr / 10 rx = rx + 1 WEND END IF IF xunitovr < 1.5 THEN xunitovr = 1 IF xunitovr >= 1.5 AND xunitovr < 3.5 THEN xunitovr = 2 IF xunitovr >= 3.5 AND xunitovr < 7.5 THEN xunitovr = 5 IF xunitovr >= 7.5 THEN xunitovr = 10 xunitovr = xunitovr * 10 ^ rx IF yunitovr < 1 THEN WHILE yunitovr < 1 yunitovr = yunitovr * 10 ry = ry - 1 WEND END IF IF yunitovr >= 10 THEN WHILE yunitovr >= 10 yunitovr = yunitovr / 10 ry = ry + 1 WEND END IF IF yunitovr < 1.5 THEN yunitovr = 1 IF yunitovr >= 1.5 AND yunitovr < 3.5 THEN yunitovr = 2 IF yunitovr >= 3.5 AND yunitovr < 7.5 THEN yunitovr = 5 IF yunitovr >= 7.5 THEN yunitovr = 10 yunitovr = yunitovr * 10 ^ ry END IF FOR x = (INT(xmin / xunitovr) - 1) * xunitovr TO (INT(xmax / xunitovr) + 1) * xunitovr STEP xunitovr LINE ((x - xmin) / (xmax - xmin) * sx, 0)-((x - xmin) / (xmax - xmin) * sx, sy), gridc NEXT x FOR y = (INT(ymin / yunitovr) - 1) * yunitovr TO (INT(ymax / yunitovr) + 1) * yunitovr STEP yunitovr LINE (0, sy - ((y - ymin) / (ymax - ymin)) * sy)-(sx, sy - ((y - ymin) / (ymax - ymin)) * sy), gridc NEXT y x = 50 y = 50 c = 0 WHILE c < 3 x = x + 1 IF c = 1 THEN xb = x + 1 IF POINT(x, y) = axisc THEN c = 0 IF POINT(x, y) = gridc THEN c = c + 1 WEND c = 0 x = xb WHILE c < 3 y = y + 1 IF c = 1 THEN yb = y + 1 IF POINT(x, y) = axisc THEN c = 0 IF POINT(x, y) = gridc THEN c = c + 1 WEND xb = xb + 16 yb = yb + 32 fx = INT(xb / 8) fy = INT(yb / 16) xb = fx * 8 yb = fy * 16 IF xmin <= 0 AND xmax - xunitovr >= 0 THEN px = ((0 - xmin) / (xmax - xmin)) * sx FOR y = 20 TO sy IF POINT(px + 2, y) = gridc THEN pprint px, y - 19, STR$(INT((((sy - y) * (ymax - ymin)) / sy + ymin) / yunitovr + yunitovr * .1) * yunitovr) NEXT y ELSE FOR y = 20 TO sy IF POINT(2, y) = gridc THEN pprint 0, y - 19, STR$(INT((((sy - y) * (ymax - ymin)) / sy + ymin) / yunitovr + yunitovr * .1) * yunitovr) NEXT y END IF IF ymin < 0 AND ymax - yunitovr >= 0 THEN py = sy - ((0 - ymin) / (ymax - ymin)) * sy FOR x = 0 TO sx IF POINT(x, py + 2) = gridc THEN pprint x, py + 2, STR$(INT((((x) * (xmax - xmin)) / sx + xmin) / xunitovr + xunitovr * .1) * xunitovr) NEXT x ELSE FOR x = 0 TO sx IF POINT(x, 2) = gridc THEN pprint x, sy - 18, STR$(INT((((x) * (xmax - xmin)) / sx + xmin) / xunitovr + xunitovr * .1) * xunitovr) NEXT x END IF pprint 610, 232, "x" pprint 308, 10, "y" pprint 200, 140, "y = x + 2" pprint 240, 130, "2" rep: undefval = xmin - 1 xb = xmin IF xmin <> undefval THEN yb = xmin ^ 2 + 2 ELSE skip = 1 END IF gradx = (xmax - xmin) / sx FOR x = (xmin + gradx) TO xmax STEP gradx IF x <> undefval THEN y = x ^ 2 + 2 ELSE skip = 1 END IF IF y <= ymax AND y >= ymin AND skip = 0 THEN LINE (((xb - xmin) / (xmax - xmin)) * sx, sy - ((yb - ymin) / (ymax - ymin)) * sy)-(((x - xmin) / (xmax - xmin)) * sx, sy - ((y - ymin) / (ymax - ymin)) * sy), 15 yb = y xb = x IF skip = 1 THEN skip = 0 NEXT x WHILE INKEY$ = "" WEND GOTO rep SUB pprint (x, y, A$) SHARED fy, fx, xb, yb, sx, sy DIM B(16) AS LONG A$ = LTRIM$(RTRIM$(A$)) FOR d = 1 TO LEN(A$) LOCATE fy, fx PRINT MID$(A$, d, 1) REM LINE (xb - 10, yb - 18)-(xb - 1, yb - 1), 3, B GET (xb - 9, yb - 17)-(xb - 2, yb - 2), B IF (x + d * 8) <= sx - 8 AND y <= sy - 16 THEN PUT (x + d * 8, y), B, PSET NEXT d LOCATE fy, fx PRINT " " END SUB