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
Attractor Formulas
Libraries
How it works together
Description function
Special Features, Notes...
Compatibility
Fractal Type Reference
Tutorials
Appendix
CHAOSPRO 4.0
Release 4.0
.

Libraries


Similar to other programming languages ChaosPro supports "external" functions through the use of libraries:
That means, somebody can write functions which perform special calculations, for example "Octonion" math: Then these functions can be put into a library (which looks very similar to a normal formula file) which other people can use: They simply use an import-statement to make use of all functions inside the library.

A library looks as follows:

def_library {

	complex fr_add(complex a,complex b)
	{
	complex d;
	
		d=a+b;
		return(d);
	}
	complex fr_sub(complex a,complex b)
	{
		return(a-b);
	}
	complex fr_mult(complex a,complex b)
	{
		return(a*b);
	}
	complex fr_div(complex a,complex b)
	{
		return(a/b);
	}
}

A library class can contain any function you like. There is no predefined function like "init" which you have to provide.

Libraries have several restrictions:

  • They may not use any class local variables, only function local variables (see function fr_add above).
  • As a consequence, they cannot define parameters.
  • They cannot reference any predefined variable (like pixel, z, angle).

Libraries and the import-statement work similar to an include file and the #include statement in the programming language C: But using the import statement you can only import a well defined library class, that means, a library class which has been successfully compiled - unlike to the programming language C, where any piece of code can be imported.

Of course, the #include statement provided by C/C++ is more powerful, but one drawback was that compilation times increased because the include files were simply "included". And due to that those compilers had to provide mechanisms in order to speed up that process: They implemented so called "precompiled headers". I did not want to complicate things that much, and so I decided that one can import only a successfully compiled library class.

ChaosPro will import (and thus compile) only the functions from a library which are actually used in your formula. So if you import a huge library class with many functions, don't worry about compilation times: Of course, compiling will take longer, but only the functions which your formula actually uses are imported and thus increase the compilation time.