Cylon



// adjust the Horizontal msg pos // adjust the Verticle msg pos
{If you can read this, your browser dosen`t support Java.}
I Liked Battlestar Galactica

I   m   p   e   r   v   i   o   u   s     L   e   a   d   e   r



A relative of the ticker tape applets. Here, the letters are stationary while the color changes. The name refers to the similarity of the the result to the Cylon ("TV series 'Battlestar Galactica'") "eyes". Look Down for a short discussion of some interesting technical issues that arrose in writing this applet.



The source (.java) and binary (.class) files are free for the taking. Have fun. If you think of any unusual ways to use them (or how to change the displayed font) drop me a line.

PS I am thinking of appending a wav of the cylons saying "By your command!"

Cylon.class Cylon.java


HTML Code

<APPLET code="Cylon.class" width=600 height=40 >
<param name=MSG value="By Your Command.">
<param name=PauseIn value="10">
<param name=BG_Color value="black">
<param name=FG_Color value="red">
<param name=SPACEING value="24"> // adjust the inter-char spacing
<param name=DeltaH value="0"> // adjust the Horizontal msg pos
<param name=DeltaV value="-20"> // adjust the Verticle msg pos
</APPLET>




This applet presented an interesting timing problem which neccessitated overriding the nomal Graphics "Update" call to prevent screen erasure before repainting, and buffering the writing to eliminate the possibility of "seeing" the screen being repainted in each step.

Running this applet involves:


Repainting the screen involves 3 internal rountines: repaint(), update(Graphics g); and paint(Graphics g). Repaint informs the Java Virtual Machine (JVM) that the screen is going to be updated. To provide this, the JVM gets the platform information and calls "update(Graphics g)". Update erases the screen, and calls "paint(Graphics g)" to re-draw it.

Normally, the only routines a Java programmer is concerned about are "repaint" and "paint". As stated above, "repaint()" initiates the process, and "paint(Graphics g)" redraws the screen. Since the purpose of running an Applet is to display somthing just calculated, all programs over-ride the internal "paint" routine with a new paint routine placed in the code.

In this case, the update routine also had to be over-ridden. To give the effect desired, the forground color has to be changed for each character. Also the pointer that locates the character position has to he calculated for each one. Each of these steps takes time. When the screen is erased first the delays associated with this procedure become noticible. That is, you see the erasure and see each character being reprinted. However, since the letters do not move, there is actually no need to erase them. The letter in the new color can print right over the old letter giving part of the effect desired. Preventing the erasure is obtained by defining our own update routine which only calls paint.

That left the seeing of each individual letter being printed. This is eliminated by first printing the characters to a buffer, and then dumping the buffer, en masse on the screen. This can be done quick enough to make the change seem continuous for the entire message.

The last problem was the calculation time placing a lower limit on the speed the sceen could be updated. Initially, the background colors were rotated to the correct character for each step. To speed up this process the background colors were kept in a static vector and a pointer to the first color was rotated. This reduced the calculations per step for this portion of process from being proportional to the number of characters in the message to being of order 1.

The last problem, that of setting the Font and its parameters in the buffer, wasn't solved. Since i liked the result, I stopped at this point. If anyone knows how to do this, I would appreciate an e-mail.

Carl