home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Anachriz / programming / FireApplet.java.txt < prev    next >
Encoding:
Text File  |  2000-05-25  |  4.5 KB  |  133 lines

  1. // Fire applet by Anarchriz (c) 1998. All rights reserved. Contact me for more info.
  2.  
  3. import java.awt.*;
  4. import java.applet.*;
  5.  
  6. public class FireApplet extends AnimatedApplet {
  7.     private int[] pixelMap1;
  8.     private int[] pixelMap2;
  9.     private int[] temp;
  10.     private int[] palette=new int[0x200];
  11.     private int realWidth;
  12.     private int realHeight;
  13.     private int numberOfSources=25;
  14.     private int widthSource=4;
  15.     private int initHeat=0x100;
  16.     private int blackDist=10;
  17.     private boolean doubleSize=false;
  18.     private boolean clipFire=true;
  19.     
  20.     private int heatWidth, position, convert;
  21.  
  22.     public void init(){
  23.         super.init();
  24.         
  25.         String para1=getParameter("doubleSize");
  26.         String para2=getParameter("clipFire");
  27.         if (para1!=null) if (para1.equals("true")) doubleSize=true;
  28.         if (para2!=null) if (para2.equals("false")) clipFire=false;
  29.         
  30.         if (doubleSize) {
  31.             realWidth=width/2;
  32.             realHeight=height/2;
  33.             numberOfSources/=2;
  34.             blackDist/=2;
  35.             widthSource/=2;
  36.         }
  37.         else {
  38.             realWidth=width;
  39.             realHeight=height;
  40.         }
  41.         pixelMap1=new int[realWidth*(realHeight+blackDist)];
  42.         pixelMap2=new int[realWidth*(realHeight+blackDist)];
  43.         
  44.         // Init pixel arrays to zero (black)
  45.         for (int i=0; i<pixels.length; i++) pixels[i]=0;
  46.         for (int i=0; i<pixelMap1.length; i++){
  47.             pixelMap1[i]=0;
  48.             pixelMap2[i]=0;
  49.         }
  50.  
  51.         // Init the Palette
  52.         for (int i=0; i<palette.length; i++) palette[i]=0;
  53.         for (int i=0; i<0x10; i++){
  54.             palette[i]=0;
  55.         }
  56.         for (int i=0x10; i<0x50; i++){
  57.             palette[i]=((i-0x10)*4)<<16;
  58.         }
  59.         for (int i=0x30; i<0x70; i++){
  60.             if (palette[i]!=0) palette[i]=palette[i]+(((i-0x30)*4)<<8);
  61.             else palette[i]=0xFF0000+(((i-0x30)*4)<<8);
  62.         }
  63.         for (int i=0x70; i<0xB0; i++){
  64.             palette[i]=0xFFFF00+((i-0x70)*4);
  65.         }   
  66.         
  67.         setHotSpots();
  68.     }
  69.     
  70.     public void setHotSpots(){
  71.         // Set 'hot' points/lines
  72.         for (int a=0; a<numberOfSources; a++){
  73.             if (clipFire){
  74.                 heatWidth=realWidth-widthSource-8;
  75.                 position=6+(int)(heatWidth*Math.random());
  76.             }
  77.             else {
  78.                 heatWidth=realWidth-widthSource;
  79.                 position=(int)(heatWidth*Math.random());
  80.             }
  81.             for (int i=0; i<widthSource; i++){
  82.                 pixelMap1[(pixelMap1.length-realWidth-1)+i+position]=initHeat;
  83.                 pixelMap1[(pixelMap1.length-2*realWidth-1)+i+position]=initHeat;
  84.             }
  85.         }
  86.     }
  87.     
  88.     public void loop(){
  89.         temp=pixelMap1;
  90.  
  91.         for (int i=(pixelMap1.length-1-realWidth-1); i>=realWidth+1; i--){
  92.             //For each pixel from pixelMap1 is the average of its environment calculated...
  93.             int average=(pixelMap1[i-realWidth-1]+pixelMap1[i-realWidth]+pixelMap1[i-realWidth+1]+
  94.                 pixelMap1[i-1]+pixelMap1[i+1]+
  95.                 pixelMap1[i+realWidth-1]+pixelMap1[i+realWidth]+pixelMap1[i+realWidth+1])>>3;
  96.             //... and put one line higher in pixelMap2 
  97.             pixelMap2[i-realWidth]=average;
  98.  
  99.             //Convert heat numbers to 'real' colors in the pixels array
  100.             if (i<realWidth*realHeight){
  101.                 if (!doubleSize){
  102.                     if (average>=0xB0) pixels[i]=0xFFFFFF;
  103.                     else pixels[i]=palette[average];
  104.                 }
  105.                 else {
  106.                     convert=(i-i%realWidth)*4+(i%realWidth)*2;
  107.                     if (average>=0xB0) {
  108.                         pixels[convert]=0xFFFFFF;
  109.                         pixels[convert+1]=0xFFFFFF;
  110.                         pixels[convert+width]=0xFFFFFF;
  111.                         pixels[convert+width+1]=0xFFFFFF;
  112.                     }
  113.                     else {
  114.                         pixels[convert]=palette[average];
  115.                         pixels[convert+1]=palette[average];
  116.                         pixels[convert+width]=palette[average];
  117.                         pixels[convert+width+1]=palette[average];
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.  
  123.         pixelMap1=pixelMap2;
  124.         pixelMap2=temp;
  125.         for (int i=0; i<pixelMap2.length; i++) pixelMap2[i]=0;
  126.  
  127.         setHotSpots();
  128.         
  129.         newPixels();
  130.         repaint();
  131.     }
  132. }
  133.