Click here to Skip to main content
Licence CPOL
First Posted 25 Dec 2009
Views 10,351
Downloads 238
Bookmarked 11 times

Fire Effect Created by Bitmap

By | 25 Dec 2009 | Article
Shows you how to make a simple fire effect

Introduction

It's really hard to simulate fire, so I want to find a simple way to implement simulating the fire effect by bitmap.

Background

It will take a long time to become familiar with dib's API. Bitmaps and palettes are both potentially the most useful part and most confusing parts of the GDI subsystem to neophyte coders.

Principle

This is a simple application and the effect is not very good. I only want to find a better way to realize it. About this demo, I don't want to waste much of my time. So, sorry everyone. Now I'll have a short analysis about this app.

The main thinking of the demo is alert the bits of bitmap, the bits of DIB.

First I draw two lines at the bottom. Sorry that I use too many digits - it's easy for me, I am a special man that loves digits.

for(i=0;i<WIDTHBYTES(300)*7+20;i++)
   for(j=0;j<2;j++)
    {
    setPixel(pBits,i,j,RGB(255,max(rand()%200,80),0));
    setPixel(pBits,i,j,RGB(255,max(rand()%200,195),0)); 
    }

As we all see, the color of RED is assigned by a rand()%255, so its range is between 0~255. So that it could create many red points, we also need to create yellow points (I mean yellow color pixel) when the pixel has been created by a random number. Next, we want the pixel up. From bottom to top. Look at the snippet:

   for(i=0;i<300;i+=2)
   {
    for(j=rand()%300;j>1;j-=1)
    setPixel(pBits,i,j,getPixel(pBits,i,j-1));
   }

As the fire size is fixed, I use digit again. "300" means the height of bitmap is 300 pixels. To ensure each pixel has a different height, here use a random too. "j=rand()%300)" will create a value for j between 0~300.

Pixel could be from bottom to top now. But it doesn't fade. How do we do that? Of course, reduce the value of each pixel. FadeColor() is to do that.

void FadeColor(BYTE *pBits,int x,int y)
{
 pBits[y*300*3+x*3]=max(pBits[y*300*3+x*3]-6,0);
 pBits[y*300*3+x*3+1]=max(pBits[y*300*3+x*3+1]-6,0);
 pBits[y*300*3+x*3+2]=max(pBits[y*300*3+x*3+2]-3,0);
}

Digit "3" means the bitmap's bitcount is 24. (24/8=3). Every time reduce 6 of RGB value so that it will create a gradient. So easy!!

Want to know more? Please download the source code. I have a lot of things to do. Considering the time, I can't write too much. Thank you for all your support!!! Really! Hope to be your friend! Hope for your good vote!

History

  • 26th December, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Aric Green

Engineer
Huawei Tech. Ltd.
China China

Member

Although I was a college studnet now as the same I was also a teacher of C/C++/3DS MAX/website for National Computer Rank Examination.I began to study computer when I was a child 8 year's old.I use BASIC/C/C++/VB/VF/VC/DELPHI/.NET to programming.When in college I was the chairman of Computer Association of our school and I take part in ACM Competition twice in two years.I also was the only person who take part in the National Mathematical Contest in Modeling twice in two years of our school.I like computer programming very much.Hope to be your friend.thx!

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUse a Particle System Pinmembermykel1:02 5 Jan '10  
GeneralRe: Use a Particle System PinmemberAric Green16:02 5 Jan '10  
GeneralMy vote of 1 Pinmembergbelov1:01 26 Dec '09  
GeneralRe: My vote of 1 PinmemberAric Green3:23 26 Dec '09  
GeneralRe: My vote of 1 Pinmemberdelyk5:54 26 Dec '09  
GeneralRe: My vote of 1 PinmemberAric Green13:51 26 Dec '09  
GeneralRe: My vote of 1 PinmemberMishra Vikas2:17 29 Dec '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 26 Dec 2009
Article Copyright 2009 by Aric Green
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid