home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-01-01 | 5.2 KB | 217 lines |
- import java.awt.Graphics;
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.image.*;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Event;
- import java.awt.*;
-
- public class fuego extends java.applet.Applet implements Runnable {
-
- Thread runner;
- Font letra;
- FontMetrics fmetrics;
-
-
- Image imagenVirtual;
-
- byte PalR [];
- byte PalG [];
- byte PalB [];
- byte aux [];
- int intensidad;
- int frio;
- int alto,ancho,longitud,longReal;
- int tamTexto,estiloTexto,posX,posY,rebote,avance;
- int Rval,Gval,Bval;
- Color colorTexto;
- String st,texto,tipoLetra;
- boolean seMueve;
- Graphics pant;
-
- public void init () {
-
- ancho = this.getBounds().width;
- alto = this.getBounds().height;
-
- st = getParameter ("Rval");
- if (st == null) Rval = 1;
- else Rval = Integer.valueOf(st).intValue();
-
- st = getParameter ("Gval");
- if (st == null) Rval = 1;
- else Gval = Integer.valueOf(st).intValue();
-
- st = getParameter ("Bval");
- if (st == null) Rval = 1;
- else Bval = Integer.valueOf(st).intValue();
-
- st = getParameter ("intensidad");
- if (st == null) intensidad = 40;
- else intensidad = Integer.valueOf(st).intValue();
-
- st = getParameter ("frio");
- if (st == null) frio = 1;
- else frio = Integer.valueOf(st).intValue();
-
- st = getParameter ("texto");
- if (st != null) {
- texto = st;
-
- st = getParameter ("seMueve");
- if (st == null) seMueve = false;
- else {
- if (Integer.valueOf(st).intValue() == 1) {
- seMueve = true;
- st = getParameter ("avance");
- if (st == null) avance = 1;
- else avance = Integer.valueOf(st).intValue();
- }
- else seMueve = false;
- }
-
- st = getParameter ("colorTexto");
- if (st == null) colorTexto = Color.red;
- else colorTexto = new Color(Integer.parseInt(st,16));
-
- st = getParameter ("tamTexto");
- if (st == null) tamTexto = 15;
- else tamTexto = Integer.valueOf(st).intValue();
-
- st = getParameter ("estiloTexto");
- if (st == null) estiloTexto = 0;
- else estiloTexto = Integer.valueOf (st).intValue();
-
- st = getParameter ("tipoLetra");
- if (st == null) tipoLetra = "TimesRoman";
- else tipoLetra = st;
-
- letra = new Font (tipoLetra,estiloTexto,tamTexto);
- fmetrics = getFontMetrics (letra);
- rebote = -(fmetrics.stringWidth(texto));
-
- st = getParameter ("posX");
- if (st == null) posX = 1;
- else posX = Integer.valueOf (st).intValue();
-
- st = getParameter ("posY");
- if (st == null) posY = alto-1;
- else posY = Integer.valueOf (st).intValue();
- }
-
- if (seMueve) posX = ancho;
-
- PalR = new byte [256];
- PalG = new byte [256];
- PalB = new byte [256];
-
- longitud = ancho*alto;
- longReal = ancho*(alto+1);
-
- aux = new byte [longReal];
-
- for (int cont = 0; cont < 256; cont++) {
- PalR [cont] = (byte) (cont+Rval);
- PalG [cont] = (byte) (cont+Gval);
- PalB [cont] = (byte) (cont+Bval);
- }
-
- imagenVirtual = createImage (new MemoryImageSource (ancho,alto,new IndexColorModel(8,256,PalR,PalG,PalB),aux,0,ancho));
- }
-
- private void fuego () {
-
- int col;
-
- cambia ();
- for (int cont = ancho; cont < longitud; cont++) {
- col = (aux[cont]+aux[cont+1]+aux[cont-1]+aux[cont+ancho])>>2;
- if (col > frio) col-= frio;
- aux[cont-ancho] = (byte) col;
- }
- }
-
- private void cambia () {
-
- int tam,pos,color;
-
-
- for (int cont = 1; cont < intensidad; cont++) {
- tam = (int) Math.floor(Math.random()*15);
- pos = (int) Math.floor(Math.random()*ancho);
- color = (int) (105 + Math.floor(Math.random()*30));
- if (color >= 128) color = 0;
- for (int cont1 = pos; cont1 < (pos+tam); cont1++) {
- aux [cont1 + longitud - ancho] = (byte)color;
- }
- }
- }
-
- public void start () {
- if (runner == null) {
- runner = new Thread(this);
- runner.start ();
- }
- }
-
- public void stop () {
- if (runner != null) {
- runner.stop ();
- runner = null;
- }
- }
-
- public void run () {
- while (true) {
- repaint ();
- if (seMueve) {if (posX > rebote) posX -= avance; else posX = ancho;}
- try {Thread.sleep(15);} catch (InterruptedException e) {}
- }
- }
-
- public boolean mouseDown (Event evt, int x, int y) {
- posX = (int) (x - (fmetrics.stringWidth(texto))/2);
- posY = y;
- stop ();
- return true;
- }
-
- public boolean mouseDrag (Event evt, int x, int y) {
- posX = (int) (x - (fmetrics.stringWidth(texto))/2);
- posY = y;
- stop ();
- return true;
- }
-
- public boolean mouseUp (Event evt, int x, int y) {
- start ();
- return true;
- }
-
- public boolean mouseEnter (Event evt, int x, int y) {
- Cursor cruz = new Cursor (Cursor.MOVE_CURSOR);
- setCursor (cruz);
- return true;
- }
-
- public boolean mouseExit (Event evt, int x, int y) {
- Cursor normal = new Cursor (Cursor.DEFAULT_CURSOR);
- setCursor (normal);
- return true;
- }
-
- synchronized public void update (Graphics g) {
-
- imagenVirtual.flush();
- fuego ();
- g.setFont (letra);
- g.drawImage(imagenVirtual,0,0,this);
- g.setColor (colorTexto);
- g.drawString (texto,posX,posY);
- }
-
- public void paint (Graphics g) {
- update (g);
- }
- }