// Shadow.java import java.applet.Applet; import java.util.Random; import java.net.URL; import java.awt.*; public class Shadow extends Applet implements Runnable{ // Aquí se hará la imagen Image bufferImage; Graphics bufferGraphics; // Los mensajes private int nyos = 100; private String yo[]; // Las cadenas private Cadena mensaje[]; private boolean nuevo[]; // La imagen private Image imagen; // Un número aleatorio public Random aleatorio; // Cuenta las pasadas private int pasadas; // El thread private Thread proceso; // Inicialización general public void init(){ int p; aleatorio = new Random(); yo = new String[nyos]; yo[0] = new String("Me gusta la informática"); yo[1] = new String("Me gusta el cine"); yo[2] = new String("Me gusta la literatura"); yo[3] = new String("No me gustan las Spice Girls"); yo[4] = new String("Me gusta ser amigos de mis amigos"); yo[5] = new String("Me gusta beber moderadamente"); yo[6] = new String("A veces me gusta beber mucho"); yo[7] = new String("A veces no me gusta beber"); yo[8] = new String("Me gusta comer moderadamente"); yo[9] = new String("A veces me gusta comer mucho"); yo[10] = new String("A veces no me gusta comer"); yo[11] = new String("Me gustan las tres dimensiones"); yo[12] = new String("Soy estudiante de informática"); yo[13] = new String("Soy de España"); yo[14] = new String("Me gustan Extreme"); yo[15] = new String("Me gustan Aerosmith"); yo[16] = new String("Me gusta Juan Perro"); yo[17] = new String("No me gusta el cine comercial"); yo[18] = new String("Me gusta el cine europeo"); yo[19] = new String("Me gustan los pubs"); yo[20] = new String("No me gustan las discotecas"); yo[21] = new String("Me gustan las mujeres"); yo[22] = new String("Me gustan los fractales"); yo[23] = new String("No me gusta la violencia"); yo[24] = new String("Me gusta John Ford"); yo[25] = new String("No me gusta Jim Carrey"); yo[26] = new String("Me gusta Ernesto Sábato"); yo[27] = new String("Me gusta Cela"); yo[28] = new String("No me gusta Stephen King"); yo[29] = new String("Me gustan Skaven y Purple Motion"); yo[30] = new String("Me gustan Future Crew"); yo[31] = new String("Me gustan Iguana"); yo[32] = new String("Disfruto programando"); yo[33] = new String("Me gusta Vangelis"); yo[34] = new String("Me gusta la cultura"); yo[35] = new String("No me gusta la incultura"); yo[36] = new String("No sé si soy guapo"); yo[37] = new String("No sé si soy feo"); yo[38] = new String("Me gusta escuchar"); yo[39] = new String("Me gusta hablar"); yo[40] = new String("Me gusta jugar al rol"); yo[41] = new String("Me gusta jugar con el ordenador"); yo[42] = new String("Me gusta dormir"); yo[43] = new String("No me gusta levantarme tarde"); yo[44] = new String("Me gusta la noche"); yo[45] = new String("Me gustan las tormentas"); yo[46] = new String("Me gusta el té"); yo[47] = new String("Me gusta la fruitopía"); yo[48] = new String("No me gusta Bill Gates"); yo[49] = new String("No me gusta Microsoft"); yo[50] = new String("Me gusta Borland"); yo[51] = new String("Me gusta el Linux"); yo[52] = new String("No me gusta Windows95"); yo[53] = new String("Me gustan las X Windows"); yo[54] = new String("Sé programar en Basic"); yo[55] = new String("Sé programar en Pascal"); yo[56] = new String("Sé programar en C"); yo[57] = new String("Sé programar en C++"); yo[58] = new String("Sé programar en Java"); yo[59] = new String("Me gustan las sonrisas"); yo[60] = new String("No me gustan los lloros"); yo[61] = new String("A veces es bueno llorar"); yo[62] = new String("Me gusta la gente decidida"); yo[63] = new String("No soy muy decidido"); yo[64] = new String("Soy tímido"); yo[65] = new String("Me gusta la igualdad social"); yo[66] = new String("No me gusta la desigualdad social"); yo[67] = new String("Me gusta la mente"); yo[68] = new String("Me gusta la gente inteligente"); yo[69] = new String("Me gusta aprender"); yo[70] = new String("Me gusta enseñar"); yo[71] = new String("Me gusta pasear"); yo[72] = new String("No me gusta el nerviosismo"); yo[73] = new String("No me gustan los enterados"); yo[74] = new String("Me gustan las buenas ideas"); yo[75] = new String("Me gusta García Márquez"); yo[76] = new String("Sé programar en Lisp"); yo[77] = new String("Me gusta Lobocom"); yo[78] = new String("Me gusta la soledad"); yo[79] = new String("Soy misántropo"); yo[80] = new String("Me gusta pensar"); yo[81] = new String("Me gusta imaginar"); yo[82] = new String("Me gusta inventar mundos"); yo[83] = new String("Me gusta el frío"); yo[84] = new String("No me gusta el calor"); yo[85] = new String("Me gusta ser una sombra"); yo[86] = new String("Me gusta el chat de Lobocom"); yo[87] = new String("Me gusta ayudar a otros"); yo[88] = new String("No me gusta usar librerías de otros"); yo[89] = new String("Me gusta el Pascal"); yo[90] = new String("Me gustan los punteros"); yo[91] = new String("No sé cómo soy"); yo[92] = new String("Me gusta aprender rimas"); yo[93] = new String("Me gusta escribir"); yo[94] = new String("Me gusta mandar y recibir e-mails"); yo[95] = new String("Me gustan las sorpresas"); yo[96] = new String("No me gustan las bromas pesadas"); yo[97] = new String("No me gusta gastar bromas"); yo[98] = new String("No sé qué me gusta"); yo[99] = new String("No sé qué no me gusta"); resize(640,400); bufferImage= createImage(640,400); bufferGraphics = bufferImage.getGraphics(); bufferGraphics.setColor(Color.black); bufferGraphics.fillRect(0,0,640,400); mensaje = new Cadena[5]; p = Math.abs(aleatorio.nextInt() % nyos); mensaje[0] = new Cadena(yo[p],Color.red); nuevo = new boolean[5]; nuevo[0] = true; nuevo[1] = true; nuevo[2] = true; nuevo[3] = true; nuevo[4] = true; pasadas = 0; } // A pintar public void paint(Graphics g){ /* g.drawImage(imagen,400,0,this);*/ } // Vamos a ejecutar el thread public void run(){ Graphics g = getGraphics(); Toolkit t = getToolkit(); int cr,cg,cb,piv,p; // Bucle infinito que realiza la animación while(true){ /* try{ Thread.sleep(100); } catch (InterruptedException e){} */ if (pasadas < 500) pasadas++; // Limpiamos el buffer bufferGraphics.setColor(Color.black); bufferGraphics.fillRect(0,0,640,400); bufferGraphics.setFont(new Font("Arial",0,20)); bufferGraphics.setColor(new Color(150,0,0)); bufferGraphics.drawString("ShadowEgo",23,23); bufferGraphics.setColor(Color.red); bufferGraphics.drawString("ShadowEgo",20,20); bufferGraphics.setFont(new Font("Arial",1,14)); // vamos a trabajar con las cadenas for(piv=0;piv<5;piv++){ if (mensaje[piv]!=null){ cr = mensaje[piv].colorActual.getRed(); cg = mensaje[piv].colorActual.getGreen(); cb = mensaje[piv].colorActual.getBlue(); if (mensaje[piv].aclara){ if (cr < 250){ cr +=10; cg +=10; cb +=10; } else if (cr < 255){ cr++; cg++; cb++; } else mensaje[piv].aclara = false; } else{ // si no aclara if (cr > 250){ cr--; cg--; cb--; } else if (cr > 0){ cr-=10; cg-=10; cb-=10; } else{ p = Math.abs(aleatorio.nextInt() % nyos); mensaje[piv] = new Cadena(yo[p],Color.red); nuevo[piv] = true; } } if (!nuevo[piv]){ if (cr > 100){ bufferGraphics.setColor(new Color(cr-100,cg-100,cb-100)); bufferGraphics.drawString(mensaje[piv].laCadena,mensaje[piv].povx+3,mensaje[piv].povy+3); } mensaje[piv].colorActual = new Color(cr,cg,cb); bufferGraphics.setColor(mensaje[piv].colorActual); bufferGraphics.drawString(mensaje[piv].laCadena,mensaje[piv].povx,mensaje[piv].povy); } else nuevo[piv] = false; } // del null } // Del bucle de cadenas // Actualizamos la pantalla g.drawImage(bufferImage,0,0,this); t.sync(); switch(pasadas){ case 200 : p = Math.abs(aleatorio.nextInt() % nyos);mensaje[1] = new Cadena(yo[p],Color.red); break; case 250 : p = Math.abs(aleatorio.nextInt() % nyos);mensaje[2] = new Cadena(yo[p],Color.red); break; case 320 : p = Math.abs(aleatorio.nextInt() % nyos);mensaje[3] = new Cadena(yo[p],Color.red); break; case 400 : p = Math.abs(aleatorio.nextInt() % nyos);mensaje[4] = new Cadena(yo[p],Color.red); break; } } } // Vamos a arrancar el thread public void start(){ if (proceso == null) proceso = new Thread(this); proceso.start(); } // Vamos a detener el thread public void stop(){ if (proceso != null) proceso.stop(); proceso = null; } } class Cadena{ // true si aparece la cadena public boolean aclara; // posiciones public int povx,povy; // Y por supuesto, la cadena public String laCadena; private Random al; public Color colorActual,colorFin; public Cadena(String s,Color c){ al = new Random(); aclara = true; laCadena = s; colorFin = c; colorActual = new Color(0,0,0); povx = Math.abs(al.nextInt() % 470)+10; povy = Math.abs(al.nextInt() % 350)+10; } }