Results 1 to 1 of 1

Thread: Creating a Fire Effect for Bada Applications

  1. #1
    Join Date
    Sep 2004
    Location
    Martil
    Age
    31
    Posts
    18,723
    Likes (Given)
    0
    Likes (Received)
    457
    Dislikes (Given)
    0
    Dislikes (Received)
    0
    Rep Power
    109883

    Default Creating a Fire Effect for Bada Applications

    Create a fire effect is easy and the main idea is very simple, select one pixel (starting in the bottom row) get the average of the pixel color from the left, right, upper and lower pixels of the current pixel and changing the color of each pixel above it. Nevertheless there are other variations of this algorithm, but this is the common.
    To make our version, I create a form that implements the “IRunnable” interface and the “Run” method (then we launch it using a threat object in the entry class, see the method “OnForeground” in “FireEffect” class file). In this method we put all the logic to perform all the color operations, the above figure is translate basically to this code (see “Run” method”) :
    The fire[][] table is the buffer used to calculate all fire positions that later you draw in your canvas (I use two canvas object _pCanvas and pCanvas, for implement double buffer technique), and the size of this table is assigned in two constants “screenWidth” and “screenHeight”. And important consideration for my implementation is this: to get a better performance, we don´t draw individual points but we use rectangles of 5 x 5 pixels (constant “pixelization”), any case the logic for calculate the color is the same but in this case we use these groups and any group of 5 x5 has the same color. You can change this and test with other values to adjust performance and pixelization.
    Very important is the “Initialize” method, in which we create the color palette that we will use for our effect. The palette is an array of 256 (int) colors (in RGB format), and to get the int value for a specific color, we use the “GetRGB32” method.
    We divide our palette in five steps: from black to white passing for red, orange and yellow. If you change all these values, the palette for your fire will be different and you get blue, green, etc. fire.
    If you see the above image, you have to buttons to control the intensity of the fire, with “+” button you put more power to your fire and with “-“you quit this power. The intensity of the fire is controlled with a private attribute called “_intensity”, the default value for this is 160 and I think that the best result are if you play with values around 135 and 220.
    The code is attach to this article and has a lot of comments and is easy to follow. Enjoy and modify it and let me know your advances.


    Source :
    Code:
    http://www.badadev.com/creating-a-fire-effect-for-bada-applications/
    Attached Files Attached Files
    -
    -


    **FAQ**

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]


  2.    Advertissements


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •