Question: Playing with Fire Here is an algorithm to generate a fire-like graphical effect, using the OpenGL GLUT library we presented in class and used for
Playing with Fire Here is an algorithm to generate a fire-like graphical effect, using the OpenGL GLUT library we presented in class and used for the labs: Create a somewhat small window, say 400 x 230, referenced in HEIGHT and WIDTH. Make a 2D array of dimension HEIGHT x WIDTH to store the red color component for each pixel in the window. Do the same thing for the green color component. The blue color component will always be 0 so you don't need to make an array for blue. Initialize the values to 0. Make an idle function that calls the display() function every 5 ms (or faster if you like). You can reference how this was done in the animation problem on homework #4. In the display function: For the bottom row of pixels set the red (as referenced in the 2D array fro step 2) to a random number between 205-255. Do the same thing for the green. For each row starting from the second row from the bottom and then working up towards the top set the red component to the average of the red values for the pixel to the left, the pixel to the right, the pixel to the left and one row down, the pixel immediately one row down, and the pixel to the right and one row down. With a 50% chance subtract a random number from 1-4 from the red component. The red should never be less than 0. Repeat the above step for the green component except with a 50% change subtract a random number from 1-8. Plot a pixel with the specified red/green and blue=0 values at the corresponding coordinates in the window. The final result should look something like this (Windows binary): GLFire.zip. You can get better results with a more varied color palette to better reproduce the orange/yellow/red of an actual flame.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
