|
|
|
| Release 4.0 |
 |
Attractor - Coloring Formulas
The purpose of a coloring formula is to calculate the final color for the current pixel. The formula can
specify the color either 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(void): Called only once, i.e. when the fractal calculation starts: In this routine you can initialize variables and allocate arrays. 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.
- void loop(void): The loop function is called after the loop() function of the pixel transformation formula itself. Its purpose is to calculate a color for the current pixel. Unlike the coloring formulas of Escapetime and Quaternion the fractal type Attractor outputs a pixel in each iteration step. As such, after each iteration a color for the pixel needs to be determined.
So in this loop function you must set the 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 function is optional. You need not specify it.
Notes
In order to tell ChaosPro that this formula is ment for fractal type Attractor (and thus the proper predefined variables are defined), you need to specify the keyword ATTRACTOR 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.
Attractor_Speed(ATTRACTOR)
{
parameter int type;
parameter color solidcolor;
vector zOld;
void init(void)
{
// place initialization here
}
void loop(void)
{
// place code to be executed in every iteration loop here
if (type=="Solid")
{
pixelcolor=solidcolor;
}
else
{
index=cabs(z-zOld);
zOld=z;
}
}
void description(void)
{
this.title = "Attractor Speed";
this.helpfile = "ChaosPro.chm";
this.helptopic = "Coloring Formula";
type.caption="Coloring Mode";
type.enum="Solid\nSpeed";
type.default=0;
solidcolor.caption="Color";
solidcolor.default=(0.5,0.5,0.5);
}
}
|