Mandala Snakes

The Mandala image is built out of snakes. This version of Mandala can draw from one to four snakes (at a time). Each snake is characterized by a length and a color. The length is measured in pixels, the dots that make up the screen. The snake color depends upon the current palette. Snake parameters are set on a dialog box, started from the View|Options drop-down menu.

The Outer Circle

Whenever the Mandala window frame is created or resized, a new drawing circle is created. The circle is sized so that it fits completely within the smallest dimension of the client area of the window. All Mandalas are drawn within this circle. The perimeter of the circle is always drawn in black. The circle surrounds an X-Y coordinate system with the origin at the center of the circle. Snakes only move within the upper half of the circle. In fact, they are bounded by the upper half of the circle. They cannot have a negative Y value, or be further from the origin than the radius of the outer circle. Of course pixels are ultimately drawn over the entire circle. This is due to symmetry,  or reflections and rotations of the snakes.

As you make the outer circle smaller, you may want to reduce the snake length. The best looking Mandalas are a delicate balance between snake colors and the background color. As the background shrinks (smaller circle), it is sometimes desirable to reduce the snake length.

Iterations and Updates

The fundamental unit of change in Mandala is the iteration. An iteration is a single step movement of all of the snakes that are being drawn. This means that a pixel is added to the head of the snake, and a pixel is removed at the end of the snake. A pixel is only removed at the end of the snake when the snake has reached its full length.

The terms adding and removing, while intuitively descriptive, do not technically describe the process of combining colors on the screen. Please see the Palette page for more detailed information.

The pixel changes in a given snake are duplicated in other regions of the screen based upon the selected symmetry. In the case of 12-way symmetry, where all four snakes are being displayed, and the snakes are at full length, a given iteration implies the changing of 96 (12-way symmetry X 4 snakes X 2 ends) pixels. In practice, snakes may overlap and share a pixel location, so the number of pixels visually changing may be reduced.

An update represents a change of the actual visible window. Updates are started by a timer within the program. The update rate can be controlled with a slider control on a dialog box. At the start of each update, one or more iterations are performed, and the result of the update is the display of the cumulative results of all of the iterations per that update.

The iterations per update and update rate are both adjustable. As you vary these controls, you can create a wide range of visual effects. Increasing the iterations per update will increase the pixel per second rate, at the expense of making the snakes appear to have a jerky motion.

Drawing a Snake

A snake starts out with zero length The initial or first point of all snakes is the center of the segment or wedge. The snake has a head and a tail.   The length of all snakes is set on the Options Dialog Box.

The Mandala drawing algorithm moves through a series of operations. These operations are executed for each enabled snake (one to four).  Each complete set of operations for all snakes is called an iteration.

  1. If the snake is at the maximum length, the tail pixel is cleared of the snake color with the XOR operator. If the snake is not at full length, the tail pixel is not cleared, it does not yet exist (the tail).
  2. A new head pixel location is computed. The new pixel location is derived from the previous iteration's head pixel location. The new pixel is selected, by random, to be directly next to the previous head. A limit check is performed to make sure that the pixel does not have a negative Y value, or that it is outside of the outer circle. If the pixel is outside of the limits, another pixel is randomly selected. This process continues until a valid new pixel location is computed.
  3. Once a valid pixel location is determined, the location becomes the head of the snake. Eventually, after a number of iterations equal to the snake size, it will become the tail of the snake. The pixel at the head of the snake is combined with the snake color and the previous pixel color with the XOR operator.

The process of setting pixels is complicated by the addition of symmetry. Each pixel that is either set or cleared will give rise to additional pixels that are in the reflected or rotated segments (or wedges). Please see the symmetry page. Note that the addition of symmetry does not create more snakes. The basic snakes are reflected or rotated to create symmetric images that look as if there are many snakes, but in fact, there the are never more than the four fundamental snakes that exist within the upper half of the outer circle.

If you are interested in the operation of snakes, try selecting 2-way symmetry, one snake, and drawing within a single segment. This will draw a single snake without symmetry.

Random Numbers

  The new snake head position is derived from the previous snake head position. For any given pixel, there are 8 adjacent neighbor pixels. The new snake head is selected by random from one of these neighboring pixels. The new position must not violate one of the bounds rules. If it does, another one of the neighbors is selected. Ultimately, therefore, the snake motion, and the entire Mandala animation, is controlled exclusively by the set of random numbers produced by the random number generation software (which is part of the Windows software).

A sequence of random numbers is generated from a random number seed. This is a number given to the random number generation software before asking for random numbers. Since the seed controls the sequence of random numbers, we really have a pseudo random number generator, as opposed to true random numbers. If we control and reuse the seed, we will be able to reproduce the identical sequence of pseudo random numbers.

Mandala allows you to select one of two random number seeds. The first is a portion of the current time. Since time rarely stops, we will have an endless supply of changing seeds. The other random seed choice comes from an integer that you, the user, specify. If you supply your own seed, and do not change the size of the window (or other aspects of the Mandala), the visual pattern will repeat identically each time the Mandala is restarted. Please note that if you discover a seed that you really like, you should make sure to repeat all of the other Mandala options, including the window size. If something changes, you will not reproduce a previous Mandala animation. Random number options and parameters are specified on the View|Options dialog box.

The seed value is shown in the status bar, on the bottom of the window.

Run, Pause, Restart

When Mandala starts, the program is in run mode. The screen will be updated at the update rate, with the specified number of iterations per update. The update cycle can be paused with the View|Pause command. The cycle can be continued with the View|Run command. Drawing can be restarted with the View|Restart command.


Last update: Monday, July 30, 2001 03:17:33 PM
Back to the Mandala Home Page