Back to project page OpenGlDraw_Android.
The source code is released under:
GNU General Public License
If you think the Android project OpenGlDraw_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.opengldraw.shapes; //from w w w. j av a 2s . c om import java.util.Random; import android.graphics.Bitmap; import android.graphics.Color; public class FireEngine extends Object { private Bitmap bitmapFire; private int[] arrayColors; private static int cycle = 0; private Random rand; public FireEngine() { super(); rand = new Random(); } public Bitmap getFireBitmat() { arrayColors = new int[10000]; seed(); for(int x = 100; x < 10000; x++) { arrayColors[x] = Color.argb(0, 0, 0, 0); } bitmapFire = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);//Bitmap.createBitmap(arrayColors, 0, 100, 100, 100, Bitmap.Config.ARGB_8888); bitmapFire.setPixels(arrayColors, 0, 100, 0, 0, 100, 100); return bitmapFire; } public Bitmap morphBitmap() { int random = rand.nextInt(100); while(random < 70) {random = rand.nextInt(120);} if(cycle < random) { for(int x = 101; x < 10000; x++) { int left = x - 1; int right = x + 1; if(right > 9999) {right = 9999;} int alpha = Color.alpha(arrayColors[x]); int alphaLeft = Color.alpha(arrayColors[left]); int alphaRight = Color.alpha(arrayColors[right]); int alphaPrevRow = Color.alpha(arrayColors[x-100]); int avg = (alpha + alphaPrevRow + alphaLeft + alphaRight) / 4; arrayColors[x] = Color.argb(avg, 255, 255, 255); } cycle++; } else { for(int x = 101; x < rand.nextInt(300); x++) { arrayColors[x] = Color.argb(rand.nextInt(255), 255, 255, 255); } seed(); cycle = 0; } //bitmapFire = Bitmap.createBitmap(arrayColors, 0, 100, 100, 100, Bitmap.Config.ARGB_8888); bitmapFire.setPixels(arrayColors, 0, 100, 0, 0, 100, 100); return bitmapFire; } private void seed() { int rand1 = rand.nextInt(95); int rand2 = rand.nextInt(95); if(rand1 < rand2) { for(int x = rand1; x < rand2; x++) { arrayColors[x] = Color.argb(255, 255, 255, 255); } for(int x = 0; x < rand1; x++) { arrayColors[x] = Color.argb(0, 255, 255, 255); } for(int x = rand2; x < 100; x++) { arrayColors[x] = Color.argb(0, 255, 255, 255); } } else { for(int x = rand2; x < rand1; x++) { arrayColors[x] = Color.argb(255, 255, 255, 255); } for(int x = 0; x < rand2; x++) { arrayColors[x] = Color.argb(0, 255, 255, 255); } for(int x = rand1; x < 100; x++) { arrayColors[x] = Color.argb(0, 255, 255, 255); } } } }