/* "YuleLog.java" (created 3/1/96) */
/* Java Applet, watch the WPIX television "Yule Log" */

import java.applet.Applet;
import java.awt.*;

public class YuleLog extends java.applet.Applet implements Runnable {

 /* variables */

 /* Yule Log (brown) RGB color */
 Color      yuleLogBrown_Color;

 /* offscreen graphics context, "Yule Log" composite buffer */
 Image      offYuleLog_Image; 
 Graphics   offYuleLog_Graphics;

 /* "Yule Log" animator thread */	
 Thread     yuleLog_Thread;
 /* "Yule Log" animator thread counter */	
 int        yuleLogAnimCount;  

 /* methods invoked by Java */

 /* "init()"
  * initialize the applet */
 public void init()
 {

  /* 150 X 135 canvas */
  resize(150,135);

  /* create offscreen graphics context, "Yule Log" composite buffer */
  /* 0,0,150,135 */
  offYuleLog_Image = createImage(150,135);
  offYuleLog_Graphics = offYuleLog_Image.getGraphics();

  /* init Yule Log (brown) RGB color */
  yuleLogBrown_Color = new Color(156,49,0);

  /* init "Yule Log" animator thread counter */	
  yuleLogAnimCount = 1;

 } /* end method "init" */


 /* "start()"
  * called when the applet becomes visible on screen */
 public void start() {
		
  /* start "Yule Log" animator thread */ 
  yuleLog_Thread = new Thread(this);
  yuleLog_Thread.start();

 } /* end method "start" */


 /* "run()"
  *	called (repeatedly) by the Thread created in "start()" */
 public void run() {

  /* get a Graphics context for this component */
  Graphics  g;
		
  /* update "Yule Log" animator thread */
  while (Thread.currentThread() == yuleLog_Thread) {

   /* repaint (update) the screen */
   repaint();

   /* inc "Yule Log" anim counter (?) */
   if (yuleLogAnimCount < 4)
    yuleLogAnimCount++;
   /* reset "Yule Log" anim counter (?) */
   else if (yuleLogAnimCount == 4)
    yuleLogAnimCount = 1;

   /* begin: thread delay (125 milliseconds) */
   try {
    Thread.sleep(125);
   } catch (InterruptedException e) {
      break;
     } /* end: thread delay */

  } /* end "while (Thread.currentThread() == yuleLog_Thread)" */

 } /* end method "run" */


 /* "stop()"
  *	called when the applet is no longer visible on screen */
 public void stop() {
		
  /* stop "Yule Log" animator thread */
  yuleLog_Thread.stop(); 
  yuleLog_Thread = null;

  /* dispose offscreen Graphics Object, "Yule Log" composite buffer */
  offYuleLog_Graphics = null; 

 } /* end method "stop" */


 /* "update()"
  * update the screen */
 public void update(Graphics  g)
 { 

  /* (intercepting "update" avoids background erase) */

  /* call "paint" */
  paint(g);

 } /* end method "update" */


 /* "paint()"
  * paint the screen */
 public void paint(Graphics  g)
 {

  /* fill the entire buffer with white paint */
  offYuleLog_Graphics.setColor(Color.white);
  offYuleLog_Graphics.fillRect(0,0,150,135);
  offYuleLog_Graphics.setColor(Color.black);

  /* begin: draw flames */

  switch (yuleLogAnimCount) {
   case 1:
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(5,65,140,140);
    break; /* break "case 1" */
   case 2:
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(25,45,100,100);
    offYuleLog_Graphics.setColor(Color.red);
    offYuleLog_Graphics.fillOval(5,65,140,140);
    break; /* break "case 2" */
   case 3:
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(45,25,60,60);
    offYuleLog_Graphics.setColor(Color.red);
    offYuleLog_Graphics.fillOval(25,45,100,100);
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(5,65,140,140);
    break; /* break "case 3" */
   case 4:
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(65,10,20,20);
    offYuleLog_Graphics.setColor(Color.red);
    offYuleLog_Graphics.fillOval(45,25,60,60);
    offYuleLog_Graphics.setColor(Color.yellow);
    offYuleLog_Graphics.fillOval(25,45,100,100);
    offYuleLog_Graphics.setColor(Color.red);
    offYuleLog_Graphics.fillOval(5,65,140,140);
    break; /* break "case 4" */
  } /* end "switch (yuleLogAnimCount)" */

  /* end: draw flames */

  /* begin: draw "Yule Log" anim/image in buffer */

  /* draw log (bottom) */
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillRect(15,105,120,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawRect(15,105,120,25);
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillOval(5,105,25,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawOval(5,105,25,25);
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillOval(120,105,25,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawOval(120,105,25,25);

  /* draw log (top) */
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillRect(40,75,70,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawRect(40,75,70,25);
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillOval(30,75,25,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawOval(30,75,25,25);
  offYuleLog_Graphics.setColor(yuleLogBrown_Color);
  offYuleLog_Graphics.fillOval(95,75,25,25);
  offYuleLog_Graphics.setColor(Color.black);
  offYuleLog_Graphics.drawOval(95,75,25,25);

  /* end: draw "Yule Log" anim/image in buffer */

  /* blast "Yule Log" anim/image buffer to screen */
  g.drawImage(offYuleLog_Image,0,0,this);

 } /* end method "paint" */

} /* end class "YuleLog" */

/* end file "YuleLog.java" */

[return]