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
Quaternion Formulas
Transformations
Iteration Formulas
Coloring 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
.

Quaternion - 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. Here you 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

In order to tell ChaosPro that this formula is ment for fractal type Quaternion (and thus the proper predefined variables are defined), you need to specify the keyword QUATERNION in brackets after the formula identifier. This tells ChaosPro that pixel and z are quaternion variables (instead of complex variables) and that the other predefined variables for this fractal type are defined.

	
CP_None(QUATERNION)
{
	void final(void)
	{
		index=abs(sin((real(pixel))+cos(imag(pixel))));
	}
	void description(void)
	{
		this.title = "None";
	}
}