home *** CD-ROM | disk | FTP | other *** search
- // Fire applet by Anarchriz (c) 1998. All rights reserved. Contact me for more info.
-
- import java.awt.*;
- import java.applet.*;
-
- public class FireApplet extends AnimatedApplet {
- private int[] pixelMap1;
- private int[] pixelMap2;
- private int[] temp;
- private int[] palette=new int[0x200];
- private int realWidth;
- private int realHeight;
- private int numberOfSources=25;
- private int widthSource=4;
- private int initHeat=0x100;
- private int blackDist=10;
- private boolean doubleSize=false;
- private boolean clipFire=true;
-
- private int heatWidth, position, convert;
-
- public void init(){
- super.init();
-
- String para1=getParameter("doubleSize");
- String para2=getParameter("clipFire");
- if (para1!=null) if (para1.equals("true")) doubleSize=true;
- if (para2!=null) if (para2.equals("false")) clipFire=false;
-
- if (doubleSize) {
- realWidth=width/2;
- realHeight=height/2;
- numberOfSources/=2;
- blackDist/=2;
- widthSource/=2;
- }
- else {
- realWidth=width;
- realHeight=height;
- }
- pixelMap1=new int[realWidth*(realHeight+blackDist)];
- pixelMap2=new int[realWidth*(realHeight+blackDist)];
-
- // Init pixel arrays to zero (black)
- for (int i=0; i<pixels.length; i++) pixels[i]=0;
- for (int i=0; i<pixelMap1.length; i++){
- pixelMap1[i]=0;
- pixelMap2[i]=0;
- }
-
- // Init the Palette
- for (int i=0; i<palette.length; i++) palette[i]=0;
- for (int i=0; i<0x10; i++){
- palette[i]=0;
- }
- for (int i=0x10; i<0x50; i++){
- palette[i]=((i-0x10)*4)<<16;
- }
- for (int i=0x30; i<0x70; i++){
- if (palette[i]!=0) palette[i]=palette[i]+(((i-0x30)*4)<<8);
- else palette[i]=0xFF0000+(((i-0x30)*4)<<8);
- }
- for (int i=0x70; i<0xB0; i++){
- palette[i]=0xFFFF00+((i-0x70)*4);
- }
-
- setHotSpots();
- }
-
- public void setHotSpots(){
- // Set 'hot' points/lines
- for (int a=0; a<numberOfSources; a++){
- if (clipFire){
- heatWidth=realWidth-widthSource-8;
- position=6+(int)(heatWidth*Math.random());
- }
- else {
- heatWidth=realWidth-widthSource;
- position=(int)(heatWidth*Math.random());
- }
- for (int i=0; i<widthSource; i++){
- pixelMap1[(pixelMap1.length-realWidth-1)+i+position]=initHeat;
- pixelMap1[(pixelMap1.length-2*realWidth-1)+i+position]=initHeat;
- }
- }
- }
-
- public void loop(){
- temp=pixelMap1;
-
- for (int i=(pixelMap1.length-1-realWidth-1); i>=realWidth+1; i--){
- //For each pixel from pixelMap1 is the average of its environment calculated...
- int average=(pixelMap1[i-realWidth-1]+pixelMap1[i-realWidth]+pixelMap1[i-realWidth+1]+
- pixelMap1[i-1]+pixelMap1[i+1]+
- pixelMap1[i+realWidth-1]+pixelMap1[i+realWidth]+pixelMap1[i+realWidth+1])>>3;
- //... and put one line higher in pixelMap2
- pixelMap2[i-realWidth]=average;
-
- //Convert heat numbers to 'real' colors in the pixels array
- if (i<realWidth*realHeight){
- if (!doubleSize){
- if (average>=0xB0) pixels[i]=0xFFFFFF;
- else pixels[i]=palette[average];
- }
- else {
- convert=(i-i%realWidth)*4+(i%realWidth)*2;
- if (average>=0xB0) {
- pixels[convert]=0xFFFFFF;
- pixels[convert+1]=0xFFFFFF;
- pixels[convert+width]=0xFFFFFF;
- pixels[convert+width+1]=0xFFFFFF;
- }
- else {
- pixels[convert]=palette[average];
- pixels[convert+1]=palette[average];
- pixels[convert+width]=palette[average];
- pixels[convert+width+1]=palette[average];
- }
- }
- }
- }
-
- pixelMap1=pixelMap2;
- pixelMap2=temp;
- for (int i=0; i<pixelMap2.length; i++) pixelMap2[i]=0;
-
- setHotSpots();
-
- newPixels();
- repaint();
- }
- }
-