home *** CD-ROM | disk | FTP | other *** search
- // Simple fire applet by Anarchriz (c) 1998
-
- import java.awt.*;
- import java.applet.*;
-
- public class CircleFireApplet extends AnimatedApplet {
- private int[] pixelMap1=new int[width*height];
- private int[] pixelMap2=new int[width*height];
- private int[] temp;
- private int[] palette=new int[0x100];
- final static int numberOfSources=100;
- final static int widthSource=1;
- final static int initHeat=0xB0;
- final static int initstraal=50;
- final static int straal=50;
- final static int highBound=0xD0;
- final static double angle=0.05;
- private int teller=0;
-
- public void init(){
- super.init();
-
- pixelMap1=new int[width*height];
- pixelMap2=new int[width*height];
-
- setFPS(100);
-
- // Init pixel arrays to zero (black)
- for (int i=0; i<width*height; i++){
- pixelMap1[i]=0;
- pixelMap2[i]=0;
- pixels[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);
- }
-
- //linear co=((height/2)-y)*width+(x+(width)/2)
- // co=((height>>2)-y)*width+x+(width>>2)
- int coMapping;
- for (int x=-initstraal; x<=initstraal; x++){
- for (int y=-initstraal; y<=initstraal; y++){
- if ((x*x+y*y) <= initstraal*initstraal){
- coMapping=(y+100)*width+(x+100);
- pixelMap1[coMapping]=initHeat;
- //pixels[coMapping]=initHeat;
- }
- }
- }
- }
-
- public void loop(){
- temp=pixelMap1;
- /*for (int i=0; i<pixels.length; i++){
- pixels[i]=0;
- }
- // test part
- teller+=1;
- for (int i=0; i<pixelMap2.length; i++) {
- //if (teller==1){
- if ((pixels[i]&0xFFFFFF)>0 && i<2*width) System.out.println("ohneeheh");
- //}
- }*/
-
- int mapping, average, newy, newx, circleHeat;
- float rc, oldy, oldx;
- // van (-99,-99) tot (98,98)
- for (int x=-99; x<=98; x++){
- for (int y=-99; y<=98; y++){
- mapping=(y+100)*200+(x+100);
- if ((x*x+y*y) > straal*straal){
- average=(pixelMap1[mapping-width-1]+pixelMap1[mapping-width]+pixelMap1[mapping-width+1]+
- pixelMap1[mapping-1]+pixelMap1[mapping+1]+
- pixelMap1[mapping+width-1]+pixelMap1[mapping+width]+pixelMap1[mapping+width+1])>>3;
-
- if (x!=0 && y!=0){
- oldx=x;oldy=y;
- rc=oldy/oldx;
- }
- else if (x==0 && y!=0) rc=0; // x-as
- else if (x!=0 && y==0) rc=Integer.MAX_VALUE; // y-as
- else rc=0; // the value doesn't matter
-
- if (x>0 && y>0 && rc>=0.5 && rc<2){ //45 degrees
- newx=x+1;
- newy=y+1;
- }
- else if (y>0 && (rc>=2 || rc<-2)){ //90 degrees
- newx=x;
- newy=y+1;
- }
- else if (y>0 && x<0 && rc>=-2 && rc<-0.5){ //135 degrees
- newx=x-1;
- newy=y+1;
- }
- else if (x<0 && (rc>=-0.5 && rc<0.5)){ //180 degrees
- newx=x-1;
- newy=y;
- }
- else if (x<0 && y<0 && rc>=0.5 && rc<2){ //225 degrees
- newx=x-1;
- newy=y-1;
- }
- else if (y<0 && (rc>=2 || rc<-2)){ //270 degrees
- newx=x;
- newy=y-1;
- }
- else if (y<0 && x>0 && rc>=-2 && rc<-0.5){ //315 degrees
- newx=x+1;
- newy=y-1;
- }
- else if (x>0 && (rc>=-0.5 && rc<0.5)){ //360 degrees
- newx=x+1;
- newy=y;
- }
- else { // hopefully only for x=0 && y=0
- newx=x;
- newy=y;
- }
-
- /*newx=(int)(newx*cos(angle)+newy*sin(angle));
- newy=(int)(newy*cos(angle)-newx*sin(angle));
- if (newy<-99) newy=-98;
- if (newy>99) newy=98;
- if (newx<-99) newx=-98;
- if (newx>99) newx=98;*/
-
- mapping=(newy+100)*200+(newx+100);
- pixelMap2[mapping]=average;
-
- //Convert color numbers to 'real' colors in pixels
- if (average>=highBound) pixels[mapping]=0xFFFFFF;
- else pixels[mapping]=palette[average];
-
- if ((x*x+y*y) < (straal+1)*(straal+1)){
- mapping=(y+100)*200+(x+100);
- circleHeat=(int)(initHeat/2+(Math.random()*initHeat/2));
- pixelMap2[mapping]=circleHeat;
-
- //Convert color numbers to 'real' colors in pixels
- if (circleHeat>=highBound) pixels[mapping]=0xFFFFFF;
- else pixels[mapping]=palette[circleHeat];
- }
- }
- else {
- if((x*x+y*y) == straal*straal) {
- circleHeat=(int)(initHeat/2+(Math.random()*initHeat/2));
- pixelMap2[mapping]=circleHeat;
-
- //Convert color numbers to 'real' colors in pixels
- if (circleHeat>=highBound) pixels[mapping]=0xFFFFFF;
- else pixels[mapping]=palette[circleHeat];
- }
- else {
- pixelMap2[mapping]=initHeat;
- pixels[mapping]=0xFFFFFF;
- }
- }
- }
- }
- /*for (int i=0; i<3*width; i++){
- pixels[i]=0;
- }*/
-
- pixelMap1=pixelMap2;
- pixelMap2=temp;
- for (int i=0; i<pixelMap2.length; i++) pixelMap2[i]=0;
- newPixels();
- repaint();
- }
- }
-