Important alert: (current site time 7/16/2013 3:24:37 AM EDT)
 

winzip icon

Real-time fire (updated, 100 FPS)

Email
Submitted on: 11/28/2000 8:51:17 PM
By: Odin  
Level: Advanced
User Rating: By 37 Users
Compatibility: VB 5.0, VB 6.0
Views: 24471
(About the author)
 
     This program simulates fire. I have seen other articles that simulate fire, but this one is extremely fast (95-102 FPS on my 366) and it uses some neat API calls that most programmers probably have never seen before. I uploaded this before, but it only worked if your computer was in 24-bit colormode. I have changed it so that anyone running in 16, 24, or 32-bit colormode can see the fire perfectly. I really want to know what you think of my program. I have commented it heavily so even a beginner should be able to understand what each line does. I really hope that you will vote and leave comments, I have worked really hard to make this compatible and also the get such a high FPS so please let me know what you think.

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Real-time fire (updated, 100 FPS)
'**************************************
A few
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 9 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/28/2000 9:01:48 PMAckbar

looks cool but the fps display does not seem to work. I'd like to see how it runs on my computer.
(If this comment was disrespectful, please report it.)

 
11/28/2000 9:08:31 PMDertanyun

The FPS is determined after you hit the stop button. I hope this is the problem you are seeing and not that the FPS isn't showing at all. So hit the start button then wait a little while then click stop. The FPS will show then. If this doesn't work let me know.
(If this comment was disrespectful, please report it.)

 
11/29/2000 12:06:01 AMPaC

I get 135.50 FPS on my comp
(If this comment was disrespectful, please report it.)

 
11/29/2000 12:48:18 AMWarren

Nice effect! I get 205 fps.
(If this comment was disrespectful, please report it.)

 
11/29/2000 1:49:13 AMRad-X

I keep getting a run time error, "Subscript out of range"
(If this comment was disrespectful, please report it.)

 
11/29/2000 7:30:17 AMSteve

Really cool, I get 64 FPS on a PII 266MHz and 120 FPS on a PIII 300MHz
when compiled as a .exe.
(If this comment was disrespectful, please report it.)

 
11/29/2000 9:17:01 AMRon

Great code, Is There anyway to make it run in full screen? I tried to increase the size of the image box but got an error script out of range.

PS

FPS was between 102 and 110 on a PII 400 Win98
(If this comment was disrespectful, please report it.)

 
11/29/2000 10:05:28 AMxXx_VipeI2_xXx

Very nice! 315 FPS on my machine.
(If this comment was disrespectful, please report it.)

 
11/29/2000 12:44:07 PMDertanyun

Rad-X did you try to change the size of the fire? Because if you do, you must change all of the buffersizes and the picturebox's size on the form. If something else occured please let me know.
(If this comment was disrespectful, please report it.)

 
11/29/2000 1:02:53 PMChrisJL

Cool I get 651 FPS on my AMD-K 650 with 3D Now! MMX and 3D AGP ATI Graphics Card!
(If this comment was disrespectful, please report it.)

 
11/29/2000 1:30:23 PMSimon Price

I just clicked on the .exe, didn't change anything, and it crashed "subscript out of range" on startup. So I open the code and tried to run it from VB instead, but the exact same thing happened. I have not changed the size of the picture. I have Win98, 1024 x 786 x 24 screen res, VB6. I think fire is a cool effect and quite difficult to simulate, so I'd like to see this! See my fireworks screensaver for another cool graphics effect.
(If this comment was disrespectful, please report it.)

 
11/29/2000 1:54:43 PMMichael L. Barker

Dude! The tab key is your friend! Learn how to use it. I would have given you 5/5 for this. But because this code is just hard to read, drops it down to a 2/5.
(If this comment was disrespectful, please report it.)

 
11/29/2000 4:53:07 PMRoscket

Hi, nice code, LOVE IT! However, I want customize the size of the fire, and when i stretch the black picture box horizontally and ran it, it gave me a "Subscript out of range error." I wanted to make the fire larger horizontally. Is it possible, and if so, can you please e-mail me how (it'd be great if you send an example form too)? Thanks.
(If this comment was disrespectful, please report it.)

 
11/29/2000 4:54:29 PMDertanyun

I'm sorry Michael, but I really think you judged this a little unfairly. I worked my @$$ off to get this code to work. Then just because I use a different coding style then you, I receive a horrible rating. I even went through line by line, just so that everyone knew what was happening because I was trying to help people understand these API calls. It is very unfortunate that you were unable to vote for this code based on the work that was put into it and what it does, and rather the fact that you feel my coding style is inferior. I hope I didn't offend you or anyone else that feels my code appears a little messy because I didn't use tabs, but personally, I HATE HATE using tabs because to me it makes the code appear unorganized and when people tell me my code is worthless because of this, I get a little irritable.
(If this comment was disrespectful, please report it.)

 
11/29/2000 4:56:07 PMDertanyun

Simon, I will look through my code to see if I can locate what seems to be the problem because apparently Rad-X seems to be having a similar problem. I also run at 1024x768x24, but don't seem to run into this problem. There must be a small flaw somewhere though. I will let you know if I am able to determine what the problem is. Also, could you let me know where the error is occuring. (if possible) Thanks
(If this comment was disrespectful, please report it.)

 
11/29/2000 5:11:49 PMChris

Fire looks great Dertanyun, I wish I had a faster PC...my PIII 733 with mega everything only runs your fire at 22.48 FPS....huh?
(If this comment was disrespectful, please report it.)

 
11/29/2000 7:20:37 PMErik Forbes -- Mobius-Corp

Hey, don't listen to that michael guy. Personally, I feel that this particular piece of code is for display, not example. In other words, don't judge it by its insides.
(If this comment was disrespectful, please report it.)

 
11/29/2000 10:13:03 PMaleksisc

Cool! I've got only 18 FPS on my PIII 700 w\ 128 mem. huh!
(If this comment was disrespectful, please report it.)

 
11/30/2000 1:04:40 AMAckbar

Run the exe for the speed. In vb it's a lot slower. I ran between 12.5 and 13 fps in vb and 128+ outside. Just so you know :)
(If this comment was disrespectful, please report it.)

 
11/30/2000 12:36:36 PMDertanyun

Yes, Ackbar is correct. If you want to see the actual speed of the program you must run the exe. Thanks for voting and telling me what is wrong with my code. I hope that i can fingure out what is going wrong on Rad-X's computer and Simon's computer. I have yet to figure out what the problem seems to be. If you want to resize the fire, it takes a little more than just resizing the picturebox. (sorry about that). You have to change the picturebox to the size you want. Then at the start of each form you must set the fHeight and fWidth to the size you have made the picturebox. You must also change the three buffers (Coolingmap, NCoolingmap, and Buffer1) so that there upperbound is the fHeight * fWidth. (so if you made it 250 by 250 the buffers must be 1 to 62500)
(If this comment was disrespectful, please report it.)

 
11/30/2000 12:38:28 PMxim

Great job! The update runs a full 40 fps faster (131 fps on PII450) and looks almost perfect with the exception of an occasional pixel squaring. Love the comments and, "I don't need no steenking Tabs!" 5 globes up!
(If this comment was disrespectful, please report it.)

 
11/30/2000 2:16:01 PMSimon Price

Dertanyun, in the form frmFire_New and the sub AddHotspots, on the line that begins with Buffer1(), it crashes with subscript out of range and I think it's the y value that messes up because the variable TotInf was over 15000, way outside the picture. Hope that helps you somehow... I agree that there's no problem with leaving out tabs if that helps YOU, and I'm not voting poorly just because it crashed on me (because you couldn't test it on every machine and I hate it when people do that to me).
(If this comment was disrespectful, please report it.)

 
11/30/2000 2:21:41 PMSimon Price

Oops ignore the thing about the 15000 being outside the picture, I didn't realise you were using a 1D buffer. I wonder why it's says it's out of range then?
(If this comment was disrespectful, please report it.)

 
11/30/2000 3:07:41 PMHenYa

not to dis the code or anything..

But it's not supprising, anything can run at 100 or more FPS in a tini little window. :)

Bye.
(If this comment was disrespectful, please report it.)

 
11/30/2000 3:13:38 PMHenYa

mmm, nice.

On win2k with gforce 256 i got a range of 195-202 fps. Which is good. :)
(If this comment was disrespectful, please report it.)

 
12/1/2000 4:17:42 PMDertanyun

Simon, if you want to get rid of the error, you may enter in the On error resume next command and that top of any sub that is getting an overflow error. This will slow the program down considerably, but you can atleast see what the program looks like.
(If this comment was disrespectful, please report it.)

 
12/1/2000 4:42:26 PMDertanyun

HenYa, I was just wondering if you saw a simulation of fire written in VB that got much faster FPS, cuz that seems to be what you are implying. I was wondering that if this is so, could you let me know where it is, cuz I really like the simulation of graphics (exsp. fire) So please let me know. If you haven't thats cool and if anyone else has let me know, cuz I really want to see if there is some way I can improve my algorithm. Thanks.
(If this comment was disrespectful, please report it.)

 
12/2/2000 2:53:36 PMopello

Hey! I tried it before and got blue, green, and gray fire (looked kinda cool thow) .. but this release works on my computer (1280x1024x32) ... I got between 25 - 40 fps in IDE, and 200 - 230 in exe ... looks great! I'm on a P3 800 w/ 128 MB ram & GeForce 2 DDR 16mb ... wonder why it wasn't a little higher ... also, the frame rate lowered if I left it on for about 5 min ... again, great code :)
(If this comment was disrespectful, please report it.)

 
12/4/2000 1:16:02 PMDertanyun

Thanks to all of you people for voting and giving me feedback I was able to be selected as a contest winner! I am currently trying to design a new fire program that will be more realistic, faster, and runs in full screen mode. I'm currently at the point in finding the fastest way to render to the screen. So maybe in a few months I will have a full screen fire program, but maybe I will be unable to a faster way, so if you have any suggestions please let me know.
(If this comment was disrespectful, please report it.)

 
12/5/2000 8:40:39 AMDon

Don't feel bad I don't use tabs either cause it sux that way hehe
(If this comment was disrespectful, please report it.)

 
12/6/2000 6:48:56 PMck

Hope you tab-less guys aren't looking for a real programming job!
(If this comment was disrespectful, please report it.)

 
12/6/2000 7:52:15 PMGlenn

Hey, the code looks good, it's commented, and it works. What else do you want?! Tabs help, but not enough to influence the vote.

This .exe simulates fire better than any other I've seen on this site, and even though he's already been selected a contest winner, I'm giving him all 5 globes up here. Keep up the good work!

I'd love to see the full-screen version, or at least one that can be resized, 'cuz my only complaint with this one is the small window. That's very minor though, when you look at the actual imaging... Great job.


(If this comment was disrespectful, please report it.)

 
12/12/2000 11:15:48 AMlivinINvb

holy s*** this kicks a**!!! Even at 132 FPS!!
(If this comment was disrespectful, please report it.)

 
12/13/2000 4:12:41 AMJotaf98

Hey, I have a suggestion: if you have DX7 development kit, you'll see there a fire sample. It's not as fast and realistic as this one, but it demonstrates direct access to video memory trough arrays, which seems to be what you're looking for ;)

It runs at about 20 frames per second in a 1024x768 resolution in my computer, so don't worry about speed, you could even make a SCREEN SAVER with it! =)
(If this comment was disrespectful, please report it.)

 
12/13/2000 4:13:36 AMJotaf98

Forgot to say, great code!
(If this comment was disrespectful, please report it.)

 
12/13/2000 4:13:48 AMJotaf98

Forgot to say, great code! Can I use it in my game?
(If this comment was disrespectful, please report it.)

 
12/13/2000 9:28:50 AMSonar

Nice fire effect. Very well commented. I Get a 140 fps on my Pentium III here when I use the program's EXE in the ZIP file. But you should try this: to get a little more speed and heat, recompile the EXE with all the extra checks (overflow, array bounds, etc) removed. My fire suddenly burned 190 fps. I did not change any code for that, just removed the extra compile checks.
(If this comment was disrespectful, please report it.)

 
12/14/2000 4:05:23 PMPicklezz

Hello! Great code! I want to know how you do to update the FPS while it's running can you pls tell me that
(If this comment was disrespectful, please report it.)

 
12/14/2000 5:32:20 PMSteve Sanford

Excellent job...
(If this comment was disrespectful, please report it.)

 
12/16/2000 4:28:18 PMKristof Torfs

This is pretty cool, can you also make an alphabet out of it ? I haven't been able to check out the code.
(If this comment was disrespectful, please report it.)

 
12/16/2000 9:11:59 PMDertanyun

You can use this code as long as you give credit where credit is due. Kristof I don't understand what you want to do, but if you look at the code you can check and see. About automatic FPS, you would have to put an if statement that would check the current FPS and when it reaches a number like 200 you would have it calculate the FPS and then reset the variable that is holding the amount of time passed.
(If this comment was disrespectful, please report it.)

 
12/16/2000 10:11:19 PMshoota

hey I get 235 on a PIII 500 with 256 mem
cool
(If this comment was disrespectful, please report it.)

 
12/17/2000 5:32:13 AMlvramanan

Very Nice Code. Keep Trying a Lot of some more good stuff. Why can't u use this in place of a visual Analyzer, hope u would've seen the visualisation that comes with Realplayer 8 Basic . I got 1024 fps. I've P!!! 650e, Nvdia Rivia TNT witn 32MB RAM.
(If this comment was disrespectful, please report it.)

 
12/18/2000 9:58:36 AMKenneth Gilbert Jr.

Voodoo Banshee equals 330 FPS? Hmmm.

Anyway, I gotta say it... BURN BABY, BURN! : )
(If this comment was disrespectful, please report it.)

 
12/21/2000 1:07:19 PMDertanyun

This program doesn't take advantage of graphics cards so no matter what card you have it shouldn't effect the FPS, but I'm thinking of trying to use the DirectX fire example that comes with the SDK and seeing if I can make a fast full screen version, but I've been really busy with school and all. (Thanks Jotaf98 for the idea)
(If this comment was disrespectful, please report it.)

 
12/27/2000 12:40:13 PMFormatC

Compiled exe got 225fps on a Athlon 700... and 32fps on a p166. Removed checking (as Sonar suggested) in compile and got the p166 up to 50fps. Astounding.
(If this comment was disrespectful, please report it.)

 
2/10/2001 4:44:50 AMSKoW

nice.. 300fps on my Dual P3 in Win2k
(If this comment was disrespectful, please report it.)

 
2/10/2001 9:25:47 AMCasey Goodhew

I couldn't get it working either - I ran into the 'Script out of range' bug too. Adding On Error Resume next makes that program run, sort of. It doesn't crash but I don't see any fire and I get 0 fps. If you would like to work through this problem I can do some troubleshooting for you.

goodhewc@hotmail.com
(If this comment was disrespectful, please report it.)

 
2/10/2001 9:59:51 AMStefan

I only become 18.xx FPS on my 750 Mhz Computer, but it's not a problem. I tested it only short. I only want to tell You: This is a very great prog. Keep up this good work!
(If this comment was disrespectful, please report it.)

 
2/10/2001 11:08:31 AMViper Tec.

Ok, to ck(wrote: Hope you tab-less guys aren't looking
for a real programming job!). I do have a "real" programming job at Ayrshire Electronics in Fayetteville, AR. I don't use tabs, ever. Nobody cares. As long as it works.
(If this comment was disrespectful, please report it.)

 
2/11/2001 8:14:06 PMHANSEN2000

Nice one master!

Look into the DirectX and you'll find some features you can use for sure!

I'm looking forward to a new release with fullscreen mode.....great screensaver :_>

btw - if you ever make the fullscreen mode, then post it for WinAMP.....just an idea... :_>


HANSEN2k
(If this comment was disrespectful, please report it.)

 
2/12/2001 1:33:35 PMKevin Pirkl

Cool code... Make it resizable so I can embed it into a screen saver.
(If this comment was disrespectful, please report it.)

 
3/7/2001 4:12:13 PMDertanyun

Ok, thank you everybody for your comments. I haven't had a chance to get any real work done on a full screen version all though i have looked at my options and i will be using DX for it. Had to spend most of my time looking at schools, but that is pretty much over. I'm hoping to release it in a few months, i'm going to be working on it while i'm in my last class at high school. If you want me to notify you when it is done, just let me know, and i will tell you when it is completed. I will also try and make the updated one, sizeable for all you people who want it that way. So if you have any other suggestions, just let me know and i will try and incorporate them in.
(If this comment was disrespectful, please report it.)

 
3/2/2002 3:59:04 PMMichael Barnathan

Impressive that you can get that type of FPS without using DirectX, although with it, you can probably run a fullscreen fire demo at close to that speed. Great code.
(If this comment was disrespectful, please report it.)

 
3/13/2002 7:59:33 PMBoBocK

cool
I got 68,70 FPS on PII 266
you get 5 votes!
(If this comment was disrespectful, please report it.)

 
7/22/2002 3:07:12 AMJan Richard Bodin

I didn't get any FPS on my AMD Thunderbird 914Mhz, 256 SDRAM with a 3dFX Voodoo 5 5500 (64MD SDRAM) GFX Card. Otherwise, bautiful code. 5/5...
(If this comment was disrespectful, please report it.)

 
7/28/2002 2:20:26 PMgridrun

I noticed that, when changing the size of the image, aspect ratio must be kept, else it will lead to subscript out of range error. Example: Original Image is 100x100 twips (?), u want to make it larger, make it 200x200 or 1500x1500 or 3000x3000 and so on. Also adjust the buffer sizes accordingly, or it wont work. However, with larger images, the effect considerably slows down, I get like 300 fps on my dual pIII 1000 at 100x100 but at 500x500 the thing gets so creepy u dont even see the fire starting. I guess if you want this to run @ fullscreen would be to calculate a small image, and then stretch that to full screen resolution. Otherwise cool effect :)
(If this comment was disrespectful, please report it.)

 
11/11/2004 9:03:50 PMWeasel F. Subs

Intresting concept, and one thing I haven't got is how you came up with that. However, I have figured out how the code worked (sort of), and used it to start my own little crappy bitmap-based "graphics engine" (slow, but hey, it was frickin' hard). Could I send it to you to get your 'stamp of approval' so I can post here as a tutorial? I will give you credit, of course.
Well, on your real-time fire, I got about 310 FPS on 256MB RAM, Windows XP 2 (Home), a PII (I think), compiled with VB 6.0.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.