'=========================================================================== ' Subject: RANDOM (ROTATING) STARFIELD Date: 02-05-98 (20:08) ' Author: Kyle Petersen Code: QB, QBasic, PDS ' Origin: Kyle_Petersen@cocc.edu Packet: GRAPHICS.ABC '=========================================================================== DECLARE SUB setGrayPal () DECLARE SUB moveStars (xInc!, yInc!, zInc!) DECLARE SUB readData () DECLARE SUB transformZ (nCnt%) DECLARE SUB initStars () DECLARE SUB dispStars () DEFINT A-Z '$DYNAMIC CONST NSTARS = 50 TYPE star x AS SINGLE y AS SINGLE z AS SINGLE trueX AS INTEGER trueY AS INTEGER trueZ AS INTEGER dest AS SINGLE END TYPE DIM SHARED star(NSTARS) AS star DIM SHARED flyType DIM SHARED text$(10) flyType = 0 SCREEN 7, , 1, 0 RANDOMIZE TIMER readData initStars 'Part I flyType = 0 transformZ 0 st! = TIMER WHILE tElapse! < 5 CLS moveStars -5, 0, 0 IF tElapse! < 2 THEN LOCATE 1, 1: PRINT text$(0) ELSE LOCATE 2, 1: PRINT text$(1) END IF dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part II st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! flyType = 1 xDir! = 0 WHILE tElapse! < 15 CLS moveStars -5 + xDir!, 0, 0 dispStars IF tElapse! > 10 AND tElapse! > lastElapse! + .1 THEN xDir! = xDir! - 2 IF tElapse! > lastElapse! + .1 THEN transformZ 1: lastElapse! = tElapse! PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part III flyType = 2 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! xDir! = xDir! + 5 WHILE tElapse! < 20 CLS IF tElapse! > lastElapse! + .2 AND xDir! < 0 THEN xDir! = xDir! + 1: lastElapse! = tElapse! moveStars xDir!, 0, -.1 dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part IV flyType = 2 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! angle! = 0 WHILE tElapse! < 20 CLS IF tElapse! > lastElapse! + .1 THEN angle! = angle! + .2 IF angle! > 6.3 THEN angle! = 0 lastElapse! = tElapse! yDir! = SIN(angle!) * 10 END IF moveStars 0, yDir!, -.1 dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part X flyType = 3 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! angle! = 0 WHILE tElapse! < 20 CLS IF tElapse! > lastElapse! + .1 THEN angle! = angle! + .2 IF angle! > 6.3 THEN angle! = 0 lastElapse! = tElapse! yDir! = SIN(angle!) * 5 END IF moveStars 0, yDir!, -.1 dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part XI flyType = 3 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! angle! = 0 yDir! = 0 zDir! = -.1 WHILE tElapse! < 15 CLS IF tElapse! > lastElapse! + .1 THEN IF zDir! < 0 THEN zDir! = zDir! + .001 IF zDir! > 0 THEN zDir! = 0 lastElapse! = tElapse! END IF moveStars 0, 0, zDir! dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part XII flyType = 1 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! angle! = 0 xDir! = 0 WHILE tElapse! < 10 CLS IF tElapse! > lastElapse! + .1 THEN IF xDir! < -5 THEN xDir! = xDir! + .1 IF xDir! > -5 THEN xDir! = -5 lastElapse! = tElapse! END IF moveStars xDir!, 0, 0 dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND 'Part XIII flyType = 0 st! = TIMER et! = TIMER tElapse! = et! - st! lastElapse! = tElapse! angle! = 0 WHILE tElapse! < 10 CLS moveStars -5, 0, 0 LOCATE 1, 1: PRINT text$(2) dispStars PCOPY 1, 0 et! = TIMER tElapse! = et! - st! WEND DATA "A simple starfield..." DATA " ...Or is it?" DATA "That's All Folks!" DATA "END" SUB dispStars FOR cnt = 0 TO NSTARS - 1 x = star(cnt).trueX y = star(cnt).trueY z = star(cnt).z col = 8 IF z < 2 THEN col = 7 IF z < 1 THEN col = 15 PSET (x, y), col NEXT END SUB SUB initStars FOR cnt = 0 TO NSTARS - 1 star(cnt).x = INT(RND(1) * 320) - 160 star(cnt).y = INT(RND(1) * 200) - 100 star(cnt).z = 0 NEXT END SUB SUB moveStars (xInc!, yInc!, zInc!) FOR cnt = 0 TO NSTARS - 1 star(cnt).x = star(cnt).x + xInc! star(cnt).y = star(cnt).y + yInc! star(cnt).z = star(cnt).z + zInc! x! = star(cnt).x y! = star(cnt).y z! = star(cnt).z x! = (x! / (z! + 1)) + 160 y! = (y! / (z! + 1)) + 100 IF x! < 0 AND flyType = 0 THEN star(cnt).x = 160 star(cnt).y = INT(RND(1) * 200) - 100 star(cnt).z = 0 END IF IF x! < 0 AND flyType = 1 THEN star(cnt).z = RND(1) * 3 star(cnt).x = 160 * (star(cnt).z + 1) star(cnt).y = (INT(RND(1) * 200) - 100) * (star(cnt).z + 1) star(cnt).dest = star(cnt).z END IF IF (z! < 0 OR x! < 0 OR y! < 0 OR x! > 320 OR y! > 320) AND flyType = 2 THEN star(cnt).z = 3 star(cnt).x = (INT(RND(1) * 320) - 160) * (star(cnt).z + 1) star(cnt).y = (INT(RND(1) * 200) - 100) * (star(cnt).z + 1) END IF IF (z! < 0 OR x! < 0 OR y! < 0 OR x! > 320 OR y! > 320) AND flyType = 3 THEN star(cnt).z = 3 angle! = RND(1) * 6.3 star(cnt).x = COS(angle!) * 80 star(cnt).y = SIN(angle!) * 80 END IF x! = star(cnt).x y! = star(cnt).y z! = star(cnt).z x! = (x! / (z! + 1)) + 160 y! = (y! / (z! + 1)) + 100 star(cnt).trueX = x! star(cnt).trueY = y! NEXT END SUB SUB readData cnt = 0 DO READ a$ text$(cnt) = a$ cnt = cnt + 1 LOOP WHILE a$ <> "END" END SUB SUB transformZ (nCnt) FOR cnt = 0 TO NSTARS - 1 IF nCnt = 0 THEN star(cnt).dest = RND(1) * 3 ELSE IF star(cnt).z < star(cnt).dest THEN star(cnt).z = star(cnt).z + .1 END IF END IF NEXT END SUB