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

  1. // Simple fire applet by Anarchriz (c) 1998
  2.  
  3. import java.awt.*;
  4. import java.applet.*;
  5.  
  6. public class CircleFireApplet extends AnimatedApplet {
  7.     private int[] pixelMap1=new int[width*height];
  8.     private int[] pixelMap2=new int[width*height];
  9.     private int[] temp;
  10.     private int[] palette=new int[0x100];    
  11.     final static int numberOfSources=100;
  12.     final static int widthSource=1;
  13.     final static int initHeat=0xB0;
  14.     final static int initstraal=50;
  15.     final static int straal=50;
  16.     final static int highBound=0xD0;
  17.     final static double angle=0.05;
  18.     private int teller=0;    
  19.     
  20.     public void init(){
  21.         super.init();
  22.         
  23.         pixelMap1=new int[width*height];
  24.         pixelMap2=new int[width*height];
  25.  
  26.         setFPS(100);
  27.         
  28.         // Init pixel arrays to zero (black)      
  29.         for (int i=0; i<width*height; i++){
  30.             pixelMap1[i]=0;        
  31.             pixelMap2[i]=0;
  32.             pixels[i]=0;
  33.         }
  34.         
  35.         // Init the Palette
  36.         for (int i=0; i<palette.length; i++) palette[i]=0;
  37.         for (int i=0; i<0x10; i++){
  38.             palette[i]=0;
  39.         }
  40.         for (int i=0x10; i<0x50; i++){
  41.             palette[i]=((i-0x10)*4)<<16;
  42.         }
  43.         for (int i=0x30; i<0x70; i++){
  44.             if (palette[i]!=0) palette[i]=palette[i]+(((i-0x30)*4)<<8);
  45.             else palette[i]=0xFF0000+(((i-0x30)*4)<<8);
  46.         }
  47.         for (int i=0x70; i<0xB0; i++){
  48.             palette[i]=0xFFFF00+((i-0x70)*4);
  49.         }   
  50.                 
  51.         //linear co=((height/2)-y)*width+(x+(width)/2)
  52.         // co=((height>>2)-y)*width+x+(width>>2)
  53.         int coMapping;
  54.         for (int x=-initstraal; x<=initstraal; x++){
  55.             for (int y=-initstraal; y<=initstraal; y++){
  56.                 if ((x*x+y*y) <= initstraal*initstraal){                   
  57.                     coMapping=(y+100)*width+(x+100);
  58.                     pixelMap1[coMapping]=initHeat;
  59.                     //pixels[coMapping]=initHeat;
  60.                 }
  61.             }
  62.         } 
  63.     }
  64.  
  65.     public void loop(){
  66.         temp=pixelMap1;
  67.         /*for (int i=0; i<pixels.length; i++){
  68.             pixels[i]=0;
  69.         }
  70.         // test part
  71.         teller+=1;
  72.         for (int i=0; i<pixelMap2.length; i++) {
  73.             //if (teller==1){
  74.                 if ((pixels[i]&0xFFFFFF)>0 && i<2*width) System.out.println("ohneeheh");
  75.             //}
  76.         }*/
  77.         
  78.         int mapping, average, newy, newx, circleHeat;
  79.         float rc, oldy, oldx;
  80.         // van (-99,-99) tot (98,98)
  81.         for (int x=-99; x<=98; x++){
  82.             for (int y=-99; y<=98; y++){
  83.                 mapping=(y+100)*200+(x+100);
  84.                 if ((x*x+y*y) > straal*straal){
  85.                     average=(pixelMap1[mapping-width-1]+pixelMap1[mapping-width]+pixelMap1[mapping-width+1]+
  86.                         pixelMap1[mapping-1]+pixelMap1[mapping+1]+
  87.                         pixelMap1[mapping+width-1]+pixelMap1[mapping+width]+pixelMap1[mapping+width+1])>>3;
  88.                     
  89.                     if (x!=0 && y!=0){
  90.                         oldx=x;oldy=y;
  91.                         rc=oldy/oldx;
  92.                     }
  93.                     else if (x==0 && y!=0) rc=0; // x-as
  94.                     else if (x!=0 && y==0) rc=Integer.MAX_VALUE; // y-as
  95.                     else rc=0; // the value doesn't matter
  96.                     
  97.                     if (x>0 && y>0 && rc>=0.5 && rc<2){ //45 degrees
  98.                         newx=x+1;
  99.                         newy=y+1;
  100.                     }
  101.                     else if (y>0 && (rc>=2 || rc<-2)){ //90 degrees
  102.                         newx=x;
  103.                         newy=y+1;
  104.                     }
  105.                     else if (y>0 && x<0 && rc>=-2 && rc<-0.5){ //135 degrees
  106.                         newx=x-1;
  107.                         newy=y+1;
  108.                     }
  109.                     else if (x<0 && (rc>=-0.5 && rc<0.5)){ //180 degrees
  110.                         newx=x-1;
  111.                         newy=y;
  112.                     }
  113.                     else if (x<0 && y<0 && rc>=0.5 && rc<2){ //225 degrees
  114.                         newx=x-1;
  115.                         newy=y-1;
  116.                     }
  117.                     else if (y<0 && (rc>=2 || rc<-2)){ //270 degrees
  118.                         newx=x;
  119.                         newy=y-1;
  120.                     }
  121.                     else if (y<0 && x>0 && rc>=-2 && rc<-0.5){ //315 degrees
  122.                         newx=x+1;
  123.                         newy=y-1;
  124.                     }
  125.                     else if (x>0 && (rc>=-0.5 && rc<0.5)){ //360 degrees
  126.                         newx=x+1;
  127.                         newy=y;
  128.                     }
  129.                     else {      // hopefully only for x=0 && y=0
  130.                         newx=x;
  131.                         newy=y;
  132.                     }
  133.                     
  134.                     /*newx=(int)(newx*cos(angle)+newy*sin(angle));
  135.                     newy=(int)(newy*cos(angle)-newx*sin(angle));
  136.                     if (newy<-99) newy=-98;
  137.                     if (newy>99) newy=98;
  138.                     if (newx<-99) newx=-98;
  139.                     if (newx>99) newx=98;*/
  140.                     
  141.                     mapping=(newy+100)*200+(newx+100);
  142.                     pixelMap2[mapping]=average;
  143.                     
  144.                     //Convert color numbers to 'real' colors in pixels
  145.                     if (average>=highBound) pixels[mapping]=0xFFFFFF;
  146.                     else pixels[mapping]=palette[average];
  147.                     
  148.                     if ((x*x+y*y) < (straal+1)*(straal+1)){
  149.                         mapping=(y+100)*200+(x+100);
  150.                         circleHeat=(int)(initHeat/2+(Math.random()*initHeat/2));
  151.                         pixelMap2[mapping]=circleHeat;
  152.                         
  153.                         //Convert color numbers to 'real' colors in pixels
  154.                         if (circleHeat>=highBound) pixels[mapping]=0xFFFFFF;
  155.                         else pixels[mapping]=palette[circleHeat];
  156.                     }
  157.                 }
  158.                 else {
  159.                     if((x*x+y*y) == straal*straal) {
  160.                         circleHeat=(int)(initHeat/2+(Math.random()*initHeat/2));
  161.                         pixelMap2[mapping]=circleHeat;
  162.                         
  163.                         //Convert color numbers to 'real' colors in pixels
  164.                         if (circleHeat>=highBound) pixels[mapping]=0xFFFFFF;
  165.                         else pixels[mapping]=palette[circleHeat];
  166.                     }
  167.                     else {
  168.                         pixelMap2[mapping]=initHeat;
  169.                         pixels[mapping]=0xFFFFFF;
  170.                     }
  171.                 }
  172.             }
  173.         }
  174.         /*for (int i=0; i<3*width; i++){
  175.             pixels[i]=0;
  176.         }*/
  177.         
  178.         pixelMap1=pixelMap2;
  179.         pixelMap2=temp;
  180.         for (int i=0; i<pixelMap2.length; i++) pixelMap2[i]=0;
  181.         newPixels();
  182.         repaint();        
  183.     }
  184. }
  185.