ChaosPro Home
Introduction
What's New
Palettes
Using Formulas
Layering in ChaosPro
Rendering
Fractal Parameter Windows
Windows
Menu
3D Transformations
Animations
Formula Compiler
Writing Formulas
Language Reference
Introduction
Basic Syntax
Datatypes
Constants
Variables
Expressions
Operators
Functions
Control Structures
Compiler Directives
Functions
Interface to ChaosPro
Escapetime Formulas
Transformations
Iteration Formulas
Coloring Formulas
Quaternion Formulas
Attractor Formulas
Libraries
How it works together
Description function
Special Features, Notes...
Compatibility
Fractal Type Reference
Tutorials
Appendix
CHAOSPRO 4.0
Release 4.0
.

Escapetime - Coloring Formulas

The third type of formula supported by ChaosPro are coloring formulas. Their purpose is to calculate the final color. The formula can either specify the color directly or indirectly:

  • Directly, by setting the predefined variable pixelcolor to the desired color. A formula using this variable is called a "Direct Coloring Formula", because the palette and the global settings in the coloring tab do not have any influence on the fractal, i.e. these parameters are not used any more (unless you use the gradient function).
  • Indirectly, by setting the predefined variable index to a real value, which then acts as an index into the current palette.

    You can specify additional mapping parameters in the inside or outside tab of the fractal itself. Basically you could implement these mappings through the use of parameters in your formula, but this way some basic mappings are always available.

    If in the outside tab the parameter Mapping is set to Linear, Speed and Accel are set to 1, then the mapping is 1:1, and that means:

    • If the index returned from the coloring formula is 0, then the corresponding pixel gets colored with the very first color of the palette.

    • If the index returned from the coloring formula is 0.5, then the corresponding pixel gets colored with the color in the middle of the palette.

    • If the index returned from the coloring formula is 1, then the corresponding pixel gets colored with the last color of the palette.

    So if the coloring parameters in the inside or outside tab are set to their standard values, then the range from 0 to 1 maps exactly to the whole palette.

    Please keep in mind that the palette defines only a path through the color space: You can specify only about 230 colors using the palette editor, but these few colors simply are keyframes in the color space and get interpolated. So index=0.1332 and index=0.1333 will map to (slightly) different colors!

Back to the coloring formulas: Such a formula can contain the following functions:

  • void init_once(void): Called only once, i.e. when the fractal calculation starts: In this routine you can initialize variables and allocate arrays.
  • void init(void): The init function gets executed at the beginning of an iteration cycle for each pixel, right after the init section of the iteration formula has been executed. Its purpose is to do some initializations for the formula. Please remember that variables do not have an initial value. They are uninitialized and contain random values at the beginning. So initialize them in this function or in init_once...
  • void loop(void): The loop function gets executed in each iteration step after the bailout test (i.e. if the fractal bails out, then the loop function does not get executed in that iteration cycle).
  • void final(void): The final function gets called only if the pixel is in the correct region.

    Because you can specify different coloring formulas for the inside and outside region there are two final functions. Only at the end of the formula ChaosPro can know whether the pixel is inside (maximum number of iterations reached) or outside (maximum number of iterations not reached, iteration function bailed out). The final function of either the inside formula or the outside formula gets called: It should set the color either directly or indirectly.

    Please note that you cannot mix the use of the predefined variable index and pixelcolor in a formula: Use only one of these variables!

  • void description(void): A coloring formula also may (must) contain a function named description.

The init_once, the init and the loop function are optional. You need not specify them. But perhaps you want to color a pixel and the information at the end of the iteration cycle is not sufficient. Then you can use init and loop functions.

Notes

You can write coloring formulas specifically for the inside region or outside region. To prevent users from assigning it wrong you can specify the region type after the formula name.

In order to specify that a formula can be used only for inside coloring, you could write:

strangefrml(INSIDE)
{
   void init(void)
   {
      col=0;
   }
   void loop(void)
   {
      col=col+|z|;
   }
   void final(void)
   {
      index=col;
   }
}

The formula type after the formula identifier can be:

  • INSIDE - for formulas which are useful only for coloring the inside region of a fractal
  • OUTSIDE - for formulas which are useful only for coloring the outside region of a fractal
  • BOTH - the default (if not specified): For formulas which are useful for coloring the inside and outside region of a fractal