'=========================================================================== ' Subject: FIRE GENERATOR Date: 02-05-98 (20:08) ' Author: Kyle Petersen Code: QB, QBasic, PDS ' Origin: Kyle_Petersen@cocc.edu Packet: GRAPHICS.ABC '=========================================================================== DECLARE SUB fire (y%, x1%, x2%, cnt%) DECLARE SUB makepal (tpe%) DEFINT A-Z SCREEN 0: WIDTH 80 CLS PRINT "Choose a size for the x from 0 to 100." PRINT "25 is generally a good number. A higher" PRINT "number will result in lower, but bigger," PRINT "fire." INPUT "XSize:", xsize IF xsize < 0 OR xsize > 100 THEN xsize = 25 CLS PRINT "Choose a size for the y from 0 to 197." PRINT "150 is generally a good choice. A" PRINT "higher number will result in faster," PRINT "but smaller, fire." INPUT "YSize:", ysize IF ysize < 0 OR ysize > 197 THEN ysize = 150 CLS PRINT "Choose a palette:" PRINT "0 - Fire." PRINT "1 - Grayscale." PRINT "2 - Red." PRINT "3 - Green." PRINT "4 - Blue." PRINT "5 - Shaded primary's." INPUT "Palette #:", palet IF palet > 5 OR palet < 0 THEN palet = 0 CLS PRINT "The skip number determines how" PRINT "much the fire should decrement" PRINT "with each average. A higher" PRINT "number results in a higher" PRINT "fire. Some interesting side-" PRINT "effects will happen after the" PRINT "number 1. A range of -10 to" PRINT "10 is supported." INPUT "Skip:", cnt IF cnt < -10 OR cnt > 10 THEN cnt = 0 CLS PRINT "The number of flames can be from" PRINT "0 to 20. A 20 will cause a wall of" PRINT "flame. 10 is the recommended number." INPUT "# Flames:", amnt IF amnt < 0 OR amnt > 20 THEN amnt = 10 CLS PRINT "Movement is what determines how" PRINT "fast the flames switch positions." PRINT "Lower numbers cause faster switching." PRINT "Try 3 to begin with." INPUT "Movement:", movem IF movem < 0 OR movem > 10 THEN movem = 3 SCREEN 13 CLS RANDOMIZE TIMER DIM scx(99), scy(99), fr DIM SHARED divfour(2048) 'Make a look-up table for the divisions. 'Dividing and multiplying is one of the 'slowest operations on the pc. By making 'this table, the program can run faster. FOR t = 0 TO 2048 divfour(t) = INT(t \ 4) NEXT 'Create neat-o palette :) makepal palet x1 = 159 - (xsize / 2) 'Determine where to place the fire. x2 = 159 + (xsize / 2) FOR t = 0 TO amnt scx(t) = INT(RND(1) * xsize) + x1 scy(t) = 197 NEXT count = 1 'The Flame loop DEF SEG = &HA000 DO fire ysize, x1, x2, cnt 'The fire sub FOR t = 0 TO amnt 'Redraw the flame ignitors. IF INT(RND(1) * movem) + 1 = 1 THEN scx(t) = INT(RND(1) * xsize) + x1'Randomly move the ignitors PSET (scx(t), scy(t)), 255 'Plot em. NEXT LOOP UNTIL INKEY$ <> "" 'Continue until keypress 'Let the fire burn out... FOR t = 0 TO 127 fire ysize, x1, x2, 0 IF INKEY$ = CHR$(27) THEN EXIT FOR 'If escape hit, exit. NEXT DEF SEG 'A fairly fast fire routine 'I replaced the points with peeks and the psets with pokes 'I only multiply once and my division is stored in memory. 'I think this could be faster still... '(Without converting to assembly that is.) SUB fire (y, x1, x2, cnt) add& = (320& * y) FOR t = y TO 198 FOR x = x1 TO x2 add1& = add& + x c = divfour(PEEK(add1& - 1) + PEEK(add1& + 320) + PEEK(add1& + 1) + PEEK(add1& + 320)) IF c > 0 - cnt THEN c = c + cnt - 1 'IF c > 255 THEN c = 255 'Uncomment this if you don't want the funny 'things that run through your fire when you 'use higher numbers. (If you don't know 'what I'm talking about, don't uncomment this. 'You'll know when you see them.) POKE add1&, c NEXT add& = add& + 320 NEXT END SUB SUB makepal (tpe) OUT 968, 0 IF tpe = 0 THEN col = 0 FOR t = 0 TO 15 OUT 969, 0 OUT 969, 0 OUT 969, col col = col + 1 NEXT FOR t = 0 TO 15 OUT 969, 0 OUT 969, 0 OUT 969, col col = col - 1 NEXT col = 0 FOR t = 0 TO 63 OUT 969, col OUT 969, 0 OUT 969, 0 col = col + 1 NEXT col = 0 FOR t = 0 TO 127 OUT 969, 63 OUT 969, t \ 2 OUT 969, 0 col = col + 1 NEXT col = 0 FOR t = 0 TO 31 OUT 969, 63 OUT 969, 63 OUT 969, col col = col + 1 NEXT END IF IF tpe = 1 THEN FOR t = 0 TO 255 OUT 969, t \ 4 OUT 969, t \ 4 OUT 969, t \ 4 NEXT END IF IF tpe = 2 THEN FOR t = 0 TO 255 OUT 969, t \ 4 OUT 969, 0 OUT 969, 0 NEXT END IF IF tpe = 3 THEN FOR t = 0 TO 255 OUT 969, 0 OUT 969, t \ 4 OUT 969, 0 NEXT END IF IF tpe = 4 THEN FOR t = 0 TO 255 OUT 969, 0 OUT 969, 0 OUT 969, t \ 4 NEXT END IF IF tpe = 5 THEN 'black to red FOR t = 0 TO 31 OUT 969, t * 2 OUT 969, 0 OUT 969, 0 NEXT 'Red to blue FOR t = 0 TO 63 OUT 969, 63 - t OUT 969, 0 OUT 969, t NEXT 'Blue to green FOR t = 0 TO 63 OUT 969, 0 OUT 969, t OUT 969, 63 - t NEXT 'Green to white FOR t = 0 TO 63 OUT 969, t OUT 969, 63 OUT 969, t NEXT 'White to black FOR t = 0 TO 31 OUT 969, 62 - (t * 2) OUT 969, 62 - (t * 2) OUT 969, 62 - (t * 2) NEXT END IF END SUB