Adapting the Necker Cube Applet


This page gives instructions for embedding the Animated Necker Cube applet on your own web page and animating it with your own images.

To Make Me Happy:

Include the following HTML code somewhere on your Animated Necker Cube page:

Applet Author: <a href="http://dogfeathers.com/mark/index.html">Mark Newbold</a>

On your page, this will appear as: Applet Author: Mark Newbold

Email me the URL of your page. I may want to set up a link to your page from my pages. Also I will notify you of any significant enhancements or fixes to the applet.

The Java Classes:

These files can be found in this directory:
http://dogfeathers.com/java/necker/.

Your browser should allow you to save these files to your computer. If your computer does not allow long file names, give them short names then rename them back once you have uploaded them to your web server.
Note that the class filenames are case-sensitive.

The HTML Code:

Your web browser should have a "View Document Source" option. If you view the HTML source of my Animated Necker Cube page, you will see code similar to this:

<table border=6 width=400 align=left><tr><td>
<applet codebase="http://dogfeathers.com/java/necker" code=NeckerCube.class width=400 height=400>
<param name=BEAMOPT value=1>
<param name=IMGH1 value="http://dogfeathers.com/java/necker/JACKFLY8.GIF">
<param name=IMGV1 value="http://dogfeathers.com/java/necker/MARKDIV4.GIF">
<img src="images/NECKER.GIF" width=400 height=400>
</applet>
</tr></table>
Any text you put here will be positioned to the right of the table.
<br clear=left>

The <table> HTML tag is unnecessary -- it simply provides a nice border around the applet.

The "codebase" attribute specifies the directory on your web server where you have placed the three ".class" files. This should be a full absolute URL, beginning with "http://".

You can change the applet "width" and "height" attributes. This will change the size of the cube and beams but will not affect the sizes of the images. Making the applet too large will result in "jumpy" animation, particularly on less-powerful computers. If you are using the <table> tag, make sure its width attribute is the same as applet's width.

The applet parameters are all optional. Parameter names must be uppercase. Unrecognized parameter names are ignored.

The BEAMOPT parameter controls how the moving beams are displayed.
The following BEAMOPT values are allowed:

If the BEAMOPT parameter is missing, a value of "1" is used.

Horizontally-moving images are specified using parameters IMGH1, IMGH2, etc. There are no particular limit to how many images can be specified. Having too many images might overload a web browser that is viewing your page. The applet will keep checking for IMGH parameters sequentially until one is missing. The values must be full absolute URLs, beginning with "http://". The images files MUST be on the same web server as the java class files.

Vertically-moving images are specified using parameters IMGV1, IMGV2, etc.

No-Java Image
The <img src= .....> tag specifies an image to be shown (instead of the applet) by web browsers that don't support Java. The image should have the same width and height as the applet. I made my image by hitting my "print key" to capture some screen shots of the applet. I cut and pasted parts of two screen shots (using Photoshop) to make the final image. This was pretty easy. The text "THIS IS A GIF, NOT A JAVA APPLET" will help avoid confusion among your non-Java viewers.

Preparing Your Images:

Vertically-moving images should be tall and thin. Horizontally-moving images should be long and narrow. The line-of-motion of the horizontal images is tilted downward 7.1 degrees so it may be desirable to rotate your images clockwise by this angle.

Your final images must be sized appropriately for the cube. This is a matter of trial and error. I recommend that you work at a high resolution, and save your work at high resolution. At the end, you can copy the image to a different filename and play with the size until you get something that looks right in the cube.

The images should be made into "transparent GIF's" so that the irrelevant parts of the rectangular image are transparent. This is the really time-consuming part of the process.

I find it easiest to convert my image into 256-color indexed-color (palletized) mode before working with it. Pick a color (usually white) to represent the transparent background areas of the image. Use a good graphics program such as Adobe Photoshop or CorelDraw to change all "transparent" areas of the image to that background color. You will become very proficient at selecting areas of the image.

Make sure that none of the foreground areas of the image have that background color (change them to some slightly different color). Also get rid of any extra-light pixels on the perimeter of the image, since these give the image a cut-out appearance (change them to the background color).

Finally, use a utility such as LVIEW or Gif Construction Set to specify the background color in the GIF file.

"How-to" info about transparent GIF's can be found on the Web -- search for "transparent gif".

Java Console Output

If your browser has a "Java Console", you should activate it while debugging. It may give you some useful information about why a particular image is not showing.

Performance

If you want the smoothest possible animation, don't put any animated GIF's or other Java applets on the same page with the Necker cube.

Java Source Code

I am not making the source code available at this time.

-- THE END --


<Dogfeathers Home Page>   <Mark's Home Page>   <Mark's Java Stuff>   <Animated Necker Cube>
Email: Mark Newbold
This page URL: http://dogfeathers.com/java/neckerhow.html