'=========================================================================== ' Subject: DRAW SPHERES Date: 12-02-96 (21:03) ' Author: James Eibsch Code: QB, QBasic, PDS ' Origin: comp.lang.basic.misc Packet: EGAVGA.ABC '=========================================================================== 'Here's a little QBASIC sub to draw spheres, randomly dithered for a 'head-on lighting effect. IIRC it was originally from Acorn User 'magazine, from when I wrote schools software for the Archimedes. I 'haven't tried to optimise it. DECLARE SUB Drawsphere (x!, y!, r!) SCREEN 12 RANDOMIZE TIMER c = 0 FOR i = 0 TO 15 PALETTE i, c + c * 256 + c * 65536 c = c + 4 NEXT WHILE 1 x = RND * 640 y = RND * 480 r = RND * 80 + 10 Drawsphere x, y, r WEND SUB Drawsphere (x, y, r) t = r * r FOR i = 0 TO r FOR j = 0 TO SQR(t - i * i) c = 15 * SQR(1 - (i * i + j * j) / t) + .99 cc = INT(c) k = c - cc IF RND * y - 1 > y * k THEN cc = cc - 1 PSET (x + i, y + j), cc PSET (x - i, y + j), cc PSET (x + i, y - j), cc PSET (x - i, y - j), cc NEXT NEXT END SUB