'=========================================================================== ' Subject: FULL SCREEN FIRE SIMULATION Date: 01-23-98 (18:52) ' Author: David A. Wicker Code: QB, QBasic, PDS ' Origin: pyramax@fastlane.net Packet: GRAPHICS.ABC '=========================================================================== ' Fire Competition Entry by David A. Wicker ' Very quick fire! Change SP to any value from 5 to 20, greater than that, ' it doesn't look like very good fire. ' --------------------------------------------------------------------------- ' As always, if you borrow anything from any source code for your ' shareware projects, please give credit to the original author! ' --------------------------------------------------------------------------- DEFINT A-Z '$DYNAMIC ' These two yield maximum speed and memory DECLARE SUB RGB (N, R, G, B) ' Get in the habit of making Subprograms to handle all your GOSUB needs. ' It's much more powerful and easier to use and maintain in the future. ' Tap [F2] to see existing Subprograms and Functions. ' Use ALT-E "S" to create a new Subprogram. They can each have an argument ' saving you from having to use temporary variables in a GOSUB routine. ' Also, any variables used inside a Subprogram unless defined otherwise are ' not carried over to your main program! DEF FNR (A) = INT(RND * A) RANDOMIZE TIMER ' My little Random function routine. I like to use this instead of ' using RND* in my statements. SCREEN 13 ' Yield 320x200x256 FOR I = 0 TO 63 RGB I, I, 0, 0 RGB I + 64, 63, I, 0 NEXT ' This uses up 128 colors to make our fire, black to red to yellow SP = 5: ' Speed of Fire ' As always, you can compile this to an .EXE to see it running full speed DO FOR I = FNR(SP) TO 199 - FNR(SP) STEP SP FOR J = FNR(SP) TO 319 STEP SP A = I - FNR(64) ' FACT: Using RND inside a statement that does not return a value is =MUCH= ' quicker than putting the results in a variable. Don't believe me ? ' REM out the A=I-FNR(64) and put in a new line beneath: A=I ' How much faster does it run ? Whenever QBasic needs to store a computed ' result, it takes longer than to just compute it for a one time task like ' plotting or printing. Use this knowledge to your advantage. IF A < 0 THEN A = 0 IF A > 127 THEN A = 127 LINE (J, I)-(J - SP + FNR(SP * 2), I + FNR(SP)), A NEXT NEXT LOOP UNTIL INKEY$ > "" REM $STATIC SUB RGB (N, R, G, B) OUT &H3C8, N OUT &H3C9, R OUT &H3C9, G OUT &H3C9, B ' Routine I "earned" by trading source code of paint routine for C++ ' Apparently this is common in good QBasic programming practice so I ' will probably not give tell from where I got it again in new programs. ' =NEVER= use PALETTE. It's much too slow. END SUB