[Life3D Pic 1] Chapter 2.   Get a Life (in 3D)

 

This chapter introduces a number of programming techniques that I'll reuse frequently in subsequent chapters, including the integration of Java 3D's Canvas3D class (where a scene is rendered) with a Swing-based GUI, and displaying the scene in a full-screen window.

The scene is lit with ambient and directional lights, starts with a blue-sky background (but that can be changed), and is filled with multi-colored spheres (made with the Java 3D Sphere class). The spheres gradually rotate, change color, and fade in and out of view. These dynamic elements are driven by a simple subclass of Java 3D's Behavior acting as a timer, which triggers updates to the scene every 50 milliseconds.

The user's viewpoint (the camera) can be zoomed in and out, panned, and rotated with the mouse and control keys (courtesy of Java 3D's OrbitBehavior class).

The application is a 3D version of Conway's Game of Life, a well-known cellular automaton. The original game consists of an infinite 2D grid of cells, each of which is either alive or dead. At every time 'tick', a cell evaluates rules involving the current state of its immediate neighbors to decide whether to continue living, to die, to stay dead, or be born.

[Life3D Pic 2]

Life3D is shown in action in screenshots on the right of this page, they were taken several seconds apart.

Each cell is represented by a sphere, and the grid is a 10x10x10 lattice. When a cell is first born (or reborn) it's painted blue, then gradually changes color as it ages, through green, yellow, orange, and finally to red. When a cell die, it fades away, and when one is born, it gradually appears.

The grid is rotating randomly during all of this, changing its direction at regular intervals.

A Life3D Screensaver

I also describe how Life3D can be converted into a Windows screensaver, using JScreenSaver by Yoshinori Watanabe.

 

Downloads


Navigation:


Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page