### 3.2.1 Language Basics

The POV-Ray language consists of identifiers, reserved keywords, floating point expressions, strings, special symbols and comments. The text of a POV-Ray scene file is free format. You may put statements on separate lines or on the same line as you desire. You may add blank lines, spaces or indentations as long as you do not split any keywords or identifiers.

#### 3.2.1.1 Identifiers and Keywords

POV-Ray allows you to define identifiers for later use in the scene file. An identifier may be 1 to 40 characters long. It may consist of upper and lower case letters, the digits 0 through 9 or an underscore character ("_"). the first character must be an alphabetic character. The declaration of identifiers is covered later.

POV-Ray has a number of reserved keywords which are listed below.

a
`aa_level` `aa_threshold` `abs` `absorption` `accuracy` `acos` `acosh` `adaptive` `adc_bailout` `agate` `agate_turb` `all` | `all_intersections` `alpha` `altitude` `always_sample` `ambient` `ambient_light` `angle` `aperture` `append` `arc_angle` `area_light` `array` | `asc` `ascii` `asin` `asinh` `assumed_gamma` `atan` `atan2` `atanh` `autostop` `average`

b
`b_spline` `background` `bezier_spline` `bicubic_patch` `black_hole` `blob` `blue` | `blur_samples` `bounded_by` `box` `boxed` `bozo` `break` `brick` | `brick_size` `brightness` `brilliance` `bump_map` `bump_size` `bumps`

c
`camera` `case` `caustics` `ceil` `cells` `charset` `checker` `chr` `circular` `clipped_by` `clock` `clock_delta` `clock_on` `collect` | `color` `color_map` `colour` `colour_map` `component` `composite` `concat` `cone` `confidence` `conic_sweep` `conserve_energy` `contained_by` `control0` `control1` | `coords` `cos` `cosh` `count` `crackle` `crand` `cube` `cubic` `cubic_spline` `cubic_wave` `cutaway_textures` `cylinder` `cylindrical`

d
`debug` `declare` `default` `defined` `degrees` `density` `density_file` `density_map` | `dents` `df3` `difference` `diffuse` `dimension_size` `dimensions` `direction` `disc` | `dispersion` `dispersion_samples` `dist_exp` `distance` `div` `double_illuminate`

e
`eccentricity` `else` `emission` `end` | `error` `error_bound` `evaluate` `exp` | `expand_thresholds` `exponent` `exterior` `extinction`

f
`face_indices` `facets` `fade_color` `fade_colour` `fade_distance` `fade_power` `falloff` `falloff_angle` `false` `fclose` | `file_exists` `filter` `final_clock` `final_frame` `finish` `fisheye` `flatness` `flip` `floor` `focal_point` | `fog` `fog_alt` `fog_offset` `fog_type` `fopen` `form` `frame_number` `frequency` `fresnel` `function`

g
`gather` `gif` `global_lights` | `global_settings` `gradient` `granite` | `gray` `gray_threshold` `green`

h
`height_field` `hexagon` | `hf_gray_16` `hierarchy` | `hypercomplex` `hollow`

i
`if` `ifdef` `iff` `ifndef` `image_height` `image_map` `image_pattern` `image_width` `include` | `initial_clock` `initial_frame` `inside` `inside_vector` `int` `interior` `interior_texture` `internal` `interpolate` | `intersection` `intervals` `inverse` `ior` `irid` `irid_wavelength` `isosurface`

j
`jitter` `jpeg` | `julia` `julia_fractal` |

l
`lambda` `lathe` `leopard` `light_group` `light_source` | `linear_spline` `linear_sweep` `ln` `load_file` `local` | `location` `log` `look_at` `looks_like` `low_error_factor`

m
`macro` `magnet` `major_radius` `mandel` `map_type` `marble` `material` `material_map` `matrix` `max` `max_extent` | `max_gradient` `max_intersections` `max_iteration` `max_sample` `max_trace` `max_trace_level` `media` `media_attenuation` `media_interaction` `merge` `mesh` | `mesh2` `metallic` `method` `metric` `min` `min_extent` `minimum_reuse` `mod` `mortar`

n
`natural_spline` `nearest_count` `no` `no_bump_scale` `no_image` | `no_reflection` `no_shadow` `noise_generator` `normal` `normal_indices` | `normal_map` `normal_vectors` `number_of_waves`

o
`object` `octaves` `off` `offset` `omega` | `omnimax` `on` `once` `onion` `open` | `orient` `orientation` `orthographic`

p
`panoramic` `parallel` `parametric` `pass_through` `pattern` `perspective` `pgm` `phase` `phong` `phong_size` `photons` | `pi` `pigment` `pigment_map` `pigment_pattern` `planar` `plane` `png` `point_at` `poly` `poly_wave` `polygon` | `pot` `pow` `ppm` `precision` `precompute` `pretrace_end` `pretrace_start` `prism` `prod` `projected_through` `pwr`

q
`quadratic_spline` `quadric` `quartic` | `quaternion` `quick_color` `quick_colour` | `quilted`

r
`radial` `radians` `radiosity` `radius` `rainbow` `ramp_wave` `rand` `range` `ratio` | `read` `reciprocal` `recursion_limit` `red` `reflection` `reflection_exponent` `refraction` `render` `repeat` | `rgb` `rgbf` `rgbft` `rgbt` `right` `ripples` `rotate` `roughness`

s
`samples` `save_file` `scale` `scallop_wave` `scattering` `seed` `select` `shadowless` `sin` `sine_wave` `sinh` `size` `sky` `sky_sphere` `slice` `slope` | `slope_map` `smooth` `smooth_triangle` `solid` `sor` `spacing` `specular` `sphere` `sphere_sweep` `spherical` `spiral1` `spiral2` `spline` `split_union` `spotlight` `spotted` | `sqr` `sqrt` `statistics` `str` `strcmp` `strength` `strlen` `strlwr` `strupr` `sturm` `substr` `sum` `superellipsoid` `switch` `sys`

t
`t` `tan` `tanh` `target` `text` `texture` `texture_list` `texture_map` `tga` `thickness` | `threshold` `tiff` `tightness` `tile2` `tiles` `tolerance` `toroidal` `torus` `trace` `transform` | `translate` `transmit` `triangle` `triangle_wave` `true` `ttf` `turb_depth` `turbulence` `type`

u
`u` `u_steps` `ultra_wide_angle` `undef` `union` | `up` `use_alpha` `use_color` `use_colour` `use_index` | `utf8` `uv_indices` `uv_mapping` `uv_vectors`

v
`v` `v_steps` `val` `variance` `vaxis_rotate` | `vcross` `vdot` `version` `vertex_vectors` `vlength` | `vnormalize` `vrotate` `vstr` `vturbulence`

w
`warning` `warp` `water_level` | `waves` `while` `width` | `wood` `wrinkles` `write`

x
`x` |  |

y
`y` | `yes` |

z
`z` |  |

All reserved words are fully lower case. Therefore it is recommended that your identifiers contain at least one upper case character so it is sure to avoid conflict with reserved words.

#### 3.2.1.2 Comments

Comments are text in the scene file included to make the scene file easier to read or understand. They are ignored by the ray-tracer and are there for your information. There are two types of comments in POV-Ray.

Two slashes are used for single line comments. Anything on a line after a double slash (`//`) is ignored by the ray-tracer. For example:

     // This line is ignored

You can have scene file information on the line in front of the comment as in:

     object { FooBar } // this is an object

The other type of comment is used for multiple lines. It starts with "`/*`" and ends with "`*/`". Everything in-between is ignored. For example:

     /* These lines
        are ignored
        by the
        ray-tracer */

This can be useful if you want to temporarily remove elements from a scene file. `/*` ... `*/` comments can comment out lines containing other `//` comments and thus can be used to temporarily or permanently comment out parts of a scene. `/*` ... `*/` comments can be nested, the following is legal:

     /* This is a comment
     // This too
     /* This also */
     */

Use comments liberally and generously. Well used, they really improve the readability of scene files.

#### 3.2.1.3 Float Expressions

Many parts of the POV-Ray language require you to specify one or more floating point numbers. A floating point number is a number with a decimal point. Floats may be specified using literals, identifiers or functions which return float values. You may also create very complex float expressions from combinations of any of these using various familiar operators.

Where POV-Ray needs an integer value it allows you to specify a float value and it truncates it to an integer. When POV-Ray needs a logical or boolean value it interprets any non-zero float as true and zero as false. Because float comparisons are subject to rounding errors POV-Ray accepts values extremely close to zero as being false when doing boolean functions. Typically values whose absolute values are less than a preset value epsilon are considered false for logical expressions. The value of epsilon is system dependent but is generally about 1.0e-10. Two floats a and b are considered to be equal if abs(a-b) < epsilon.

The full syntax for float expressions is given below. Detailed explanations are given in the following sub-sections.

    FLOAT:
        NUMERIC_TERM [SIGN NUMERIC_TERM]...
    SIGN:
        + | -
    NUMERIC_TERM:
        NUMERIC_FACTOR [MULT NUMERIC_FACTOR]...
    MULT:
        * | /
    NUMERIC_FACTOR:
        FLOAT_LITERAL        |
        FLOAT_IDENTIFIER     |
        SIGN NUMERIC_FACTOR  |
        FLOAT_FUNCTION       |
        FLOAT_BUILT-IN_IDENT |
        ( FULL_EXPRESSION )  |
        ! NUMERIC_FACTOR
    VECTOR DECIMAL_POINT DOT_ITEM FLOAT_LITERAL:
        [DIGIT...] [DECIMAL_POINT] DIGIT... [EXP [SIGN] DIGIT...]
    DIGIT:
        0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
    DECIMAL_POINT:
        .
    EXP:
        e | E
    DOT_ITEM:
        x | y | z | t | u | v | red | blue | green | filter |
        transmit | gray
    FLOAT_FUNCTION:
        abs( FLOAT ) | acos( FLOAT ) | acosh( FLOAT ) | asc( STRING ) |
        asin( FLOAT ) | asinh( FLOAT ) | atan( FLOAT) | atanh( FLOAT) |
        atan2( FLOAT , FLOAT ) | ceil( FLOAT ) | cos( FLOAT ) |
        cosh( FLOAT ) | defined(IDENTIFIER ) | degrees( FLOAT ) |
        dimensions( ARRAY_IDENTIFIER ) |
        dimension_size( ARRAY_IDENTIFIER , FLOAT ) |
        div( FLOAT , FLOAT ) | exp( FLOAT ) | file_exists( STRING ) |
        floor( FLOAT ) | int( FLOAT ) | ln(Float | log( FLOAT ) |
        max( FLOAT , FLOAT, ... ) | min( FLOAT , FLOAT, ... ) |
        mod( FLOAT , FLOAT ) | pow( FLOAT , FLOAT ) |
        radians( FLOAT ) | rand( FLOAT ) | seed( FLOAT ) |
        select( FLOAT, FLOAT, FLOAT [,FLOAT]) | sin( FLOAT ) |
        sinh( FLOAT ) | sqrt( FLOAT ) | strcmp( STRING , STRING ) |
        strlen( STRING ) | tan( FLOAT ) | tanh( FLOAT ) |
        val( STRING ) | vdot( VECTOR , VECTOR ) | vlength( VECTOR ) |
        FLOAT_BUILT-IN_IDENT:
        clock | clock_delta | clock_on | false | final_clock |
        final_frame | frame_number | initial_clock | initial_frame |
        image_width | image_height | no | off | on | pi | true |
        version | yes |
    FULL_EXPRESSION:
        LOGICAL_EXPRESSION [? FULL_EXPRESSION : FULL_EXPRESSION]
    LOGICAL_EXPRESSION:
        REL_TERM [LOGICAL_OPERATOR REL_TERM]...
    LOGICAL_OPERATOR:
        & | | (note: this means an ampersand or a
                   vertical bar is a logical operator)
    REL_TERM:
        FLOAT [REL_OPERATOR FLOAT]...
    REL_OPERATOR:
        < | <= | = | >= | > | !=
    INT:
        FLOAT (note: any syntax which requires a
               integer INT will accept a FLOAT
               and it will be truncated to an
               integer internally by POV-Ray).

Note: FLOAT_IDENTIFIERS are identifiers previously declared to have float values. The DOT_ITEM syntax is actually a vector or color operator but it returns a float value. See "Vector Operators" or "Color Operators" for details. An ARRAY_IDENTIFIER is just the identifier name of a previously declared array, it does not include the `[]` braces nor the index. The syntax for STRING is in the section "Strings".

##### 3.2.1.3.1 Literals

Float literals are represented by an optional sign ("+" or "-") digits, an optional decimal point and more digits. If the number is an integer you may omit the decimal point and trailing zero. If it is all fractional you may omit the leading zero. POV-Ray supports scientific notation for very large or very small numbers. The following are all valid float literals:

`-2.0 -4 34 3.4e6 2e-5 .3 0.6`

##### 3.2.1.3.2 Identifiers

Float identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows.

    FLOAT_DECLARATION:
        #declare IDENTIFIER = EXPRESSION;    |
        #local IDENTIFIER = EXPRESSION;

Where IDENTIFIER is the name of the identifier up to 40 characters long and EXPRESSION is any valid expression which evaluates to a float value.

Note: there should be a semi-colon after the expression in a float declaration. If omitted, it generates a warning and some macros may not work properly. See " #declare vs. #local" for information on identifier scope.

Here are some examples.

     #declare Count = 0;
     #declare Rows = 5.3;
     #declare Cols = 6.15;
     #declare Number = Rows*Cols;
     #declare Count = Count+1;

As the last example shows, you can re-declare a float identifier and may use previously declared values in that re-declaration. There are several built-in identifiers which POV-Ray declares for you. See "Float Expressions: Built-in Variables" for details.

##### 3.2.1.3.3 Operators

Arithmetic expressions: Basic math expressions can be created from float literals, identifiers or functions using the following operators in this order of precedence...

`( )` | expressions in parentheses first
`+A -A !A` | unary minus, unary plus and logical "not"
`A*B A/B` | multiplication and division
`A+B A-B` | addition and subtraction

Relational, logical and conditional expressions may also be created. However there is a restriction that these types of expressions must be enclosed in parentheses first. This restriction, which is not imposed by most computer languages, is necessary because POV-Ray allows mixing of float and vector expressions. Without the parentheses there is an ambiguity problem. Parentheses are not required for the unary logical not operator "!" as shown above. The operators and their precedence are shown here.

Relational expressions: The operands are arithmetic expressions and the result is always boolean with 1 for true and 0 for false. All relational operators have the same precedence.

`(A < B)` | A is less than B
`(A <= B)` | A is less than or equal to B
`(A = B)` | A is equal to B (actually abs(A-B)<EPSILON)
`(A != B)` | A is not equal to B (actually abs(A-B)>=EPSILON)
`(A >= B)` | A is greater than or equal to B
`(A > B)` | A is greater than B

Logical expressions: The operands are converted to boolean values of 0 for false and 1 for true. The result is always boolean. All logical operators have the same precedence.

Note: these are not bit-wise operations, they are logical.

`(A & B)` | true only if both A and B are true, false otherwise
`(A | B)` | true if either A or B or both are true

Conditional expressions: The operand C is boolean while operands A and B are any expressions. The result is of the same type as A and B.

`(C ? A : B)` | if C then A else B

Assuming the various identifiers have been declared, the following are examples of valid expressions...

     1+2+3    2*5     1/3     Row*3    Col*5
     (Offset-5)/2      This/That+Other*Thing
     ((This<That) & (Other>=Thing)?Foo:Bar)

Expressions are evaluated left to right with innermost parentheses evaluated first, then unary +, - or !, then multiply or divide, then add or subtract, then relational, then logical, then conditional.

##### 3.2.1.3.4 Functions

POV-Ray defines a variety of built-in functions for manipulating floats, vectors and strings. Function calls consist of a keyword which specifies the name of the function followed by a parameter list enclosed in parentheses. Parameters are separated by commas. For example:

     keyword(param1,param2)

The following are the functions which return float values. They take one or more float, integer, vector, or string parameters. Assume that `A` and `B` are any valid expression that evaluates to a float; `I` is a float which is truncated to integer internally, `S`, `S1`, `S2` etc. are strings, and `V`, `V1`, `V2` etc. are any vector expressions.`O` is an object identifier to a pre-declared object.

`abs(A)` Absolute value of `A`. If `A` is negative, returns `-A` otherwise returns `A`.

`acos(A)` Arc-cosine of `A`. Returns the angle, measured in radians, whose cosine is `A`.

`acosh(A)` inverse hyperbolic cosine of `A`.

`asc(S)` Returns an integer value in the range 0 to 255 that is the ASCII value of the first character of the string `S`. For example `asc("ABC")` is 65 because that is the value of the character "A".

`asin(A)` Arc-sine of `A`. Returns the angle, measured in radians, whose sine is `A`.

`asinh(A)` invers hyperbolic sine of `A`

`atan2(A,B)` Arc-tangent of `(A/B)`. Returns the angle, measured in radians, whose tangent is `(A/B)`. Returns appropriate value even if `B` is zero. Use `atan2(A,1)` to compute usual atan(A) function.

`atanh(A)` invers hyperbolic tangent of `A`

`ceil(A)` Ceiling of `A`. Returns the smallest integer greater than `A`. Rounds up to the next higher integer.

`cos(A)` Cosine of `A`. Returns the cosine of the angle `A`, where `A` is measured in radians.

`cosh(A)` The hyperbolic cosine of `A`.

`defined(`IDENTIFIER`)` Returns `true` if the identifier is currently defined, `false` otherwise. This is especially useful for detecting end-of-file after a `#read` directive because the file identifier is automatically undefined when end-of-file is reached. See "The #read Directive" for details.

`degrees(A)` Convert radians to degrees. Returns the angle measured in degrees whose value in radians is `A`. Formula is degrees=A/pi*180.0.

`dimensions(` ARRAY_IDENTIFIER `)` Returns the number of dimensions of a previously declared array identifier. For example if you do `#declare MyArray=array[6][10]` then `dimensions(MyArray)` returns the value `2`.

`dimension_size(` ARRAY_IDENTIFIER, FLOAT `)` Returns the size of a given dimension of a previously declared array identifier. Dimensions are numbered left-to-right starting with 1. For example if you do `#declare MyArray=array[6][10]` then `dimension_size(MyArray,2)` returns the value `10`.

`div(A,B)` Integer division. The integer part of `(A/B)`.

`exp(A)` Exponential of `A`. Returns the value of e raised to the power `A` where e is the base of the natural logarithm, i.e. the non-repeating value approximately equal to 2.71828182846.

`file_exists(S)` Attempts to open the file specified by the string `S`. The current directory and all library directories specified by the `Library_Path` or `+L` options are also searched. See "Library Paths" for details. Returns `1` if successful and `0` if unsuccessful.

`floor(A)` Floor of `A`. Returns the largest integer less than `A`. Rounds down to the next lower integer.

`inside(O,V)` It returns either 0.0, when the vector `V` is outside the object, specified by the object-identifier `O`, or 1.0 if it is inside.

Note: `inside` does not accept object-identifiers to non-solid objects.

`int(A)` Integer part of `A`. Returns the truncated integer part of `A`. Rounds towards zero.

`log(A)` Logarithm of `A`. Returns the logarithm base 10 of the value `A`.

`ln(A)` Natural logarithm of `A`. Returns the natural logarithm base e of the value `A`.

`max(A,B,...)` Maximum of two or more float values. Returns `A` if `A` larger than `B`. Otherwise returns `B`.

`min(A,B,...)` Minimum of two or more float values. Returns `A` if `A` smaller than `B`. Otherwise returns `B`.

`mod(A,B)` Value of `A` modulo `B`. Returns the remainder after the integer division of `A`/`B`. Formula is mod=((A/B)-int(A/B))*B.

`pow(A,B)` Exponentiation. Returns the value of `A` raised to the power `B`.

Note:For a negative A and a non-integer B the function has no defined return value. The result then may depend on the platform POV-Ray is compiled on.

`radians(A)` Convert degrees to radians. Returns the angle measured in radians whose value in degrees is `A`. Formula is radians=A*pi/180.0.

`rand(I)` Returns the next pseudo-random number from the stream specified by the positive integer `I`. You must call `seed()` to initialize a random stream before calling `rand()`. The numbers are uniformly distributed, and have values between `0.0` and `1.0`, inclusively. The numbers generated by separate streams are independent random variables.

`seed(I)` Initializes a new pseudo-random stream with the initial seed value `A`. The number corresponding to this random stream is returned. Any number of pseudo-random streams may be used as shown in the example below:

      #declare R1 = seed(0);
      #declare R2 = seed(12345);
      sphere { <rand(R1), rand(R1), rand(R1)>, rand(R2) }

Multiple random generators are very useful in situations where you use `rand()` to place a group of objects, and then decide to use `rand()` in another location earlier in the file to set some colors or place another group of objects. Without separate `rand()` streams, all of your objects would move when you added more calls to `rand()`. This is very annoying.

`select(A, B, C [,D])`. It can be used with three or four parameters. `Select` compares the first argument with zero, depending on the outcome it will return `B`, `C` or `D`. `A,B,C,D` can be floats or funtions.
When used with three parameters, if `A < 0` it will return `B`, else `C` (`A >= 0`).
When used with four parameters, if `A < 0` it will return B. If `A = 0` it will return `C`. Else it will return `D` (`A > 0`).

Example:
If `A` has the consecutive values -2, -1, 0, 1, and 2 :

                               //    A =  -2 -1 0 1 2
      select (A, -1, 0, 1)     //returns  -1 -1 0 1 1
      select (A, -1, 1)        //returns  -1 -1 1 1 1

`sin(A)` Sine of `A`. Returns the sine of the angle `A`, where `A` is measured in radians.

`sinh(A)` The hyperbolic sine of `A`.

`strcmp(S1,S2)` Compare string `S1` to `S2`. Returns a float value zero if the strings are equal, a positive number if `S1` comes after `S2` in the ASCII collating sequence, else a negative number.

`strlen(S)` Length of `S`. Returns an integer value that is the number of characters in the string `S`.

`sqrt(A)` Square root of `A`. Returns the value whose square is `A`.

`tan(A)` Tangent of `A`. Returns the tangent of the angle `A`, where `A` is measured in radians.

`tanh(A)` The hyperbolic tangent of `A`.

`val(S)` Convert string `S` to float. Returns a float value that is represented by the text in string `S`. For example `val("123.45")` is 123.45 as a float.

`vdot(V1,V2)` Dot product of `V1` and `V2`. Returns a float value that is the dot product (sometimes called scalar product) of `V1` with `V2`. It is directly proportional to the length of the two vectors and the cosine of the angle between them. Formula is vdot=V1.x*V2.x + V1.y*V2.y + V1.z*V2.z. See the animated demo scene `VECT2.POV` for an illustration.

`vlength(V)` Length of `V`. Returns a float value that is the length of vector `V`. Formula is vlength=sqrt(vdot(A,A)). Can be used to compute the distance between two points. `Dist=vlength(V2-V1)`.

See section "Vector Functions" and section "String Functions" for other functions which are somewhat float-related but which return vectors and strings. In addition to the above built-in functions, you may also define your own functions using the `#macro` directive. See the section "User Defined Macros" for more details.

##### 3.2.1.3.5 Built-in Constants

Constants are:

    FLOAT_BUILT-IN_IDENT:
        false | no | off | on | pi | true | yes

The built-in constants never change value. They are defined as though the following lines were at the start of every scene.

      #declare pi = 3.1415926535897932384626;
      #declare true = 1;
      #declare yes = 1;
      #declare on = 1;
      #declare false = 0;
      #declare no = 0;
      #declare off = 0;

The built-in float identifier `pi` is obviously useful in math expressions involving circles. The built-in float identifiers `on`, `off`, `yes`, `no`, `true`, and `false` are designed for use as boolean constants.

The built-in float constats `on`, `off`, `yes`, `no`, `true`, and `false` are most often used as boolean values with object modifiers or parameters such as `sturm`, `hollow`, `hierarchy`, `smooth`, `media_attenuation`, and `media_interaction`. Whenever you see syntax of the form `keyword` `[Bool]`, if you simply specify the keyword without the optional boolean then it assumes `keyword on`. You need not use the boolean but for readability it is a good idea. You must use one of the false booleans or an expression which evaluates to zero to turn it off.

Note: some of these keywords are `on` by default, if no keyword is specified.

For example:

      object { MyBlob }                // sturm defaults off, but
                                       // hierarchy defaults on
      object { MyBlob sturm }          // turn sturm on
      object { MyBlob sturm on }       // turn sturm on
      object { MyBlob sturm off }      // turn sturm off
      object { MyBlob hierarchy }      // does nothing, hierarchy was
                                       // already on
      object { MyBlob hierarchy off }  // turn hierarchy off

##### 3.2.1.3.6 Built-in Variables

There are several built-in float variables. You can use them to specify values or to create expressions but you cannot re-declare them to change their values.

Clock-related are:

    FLOAT_BUILT-IN_IDENT:
       clock | clock_delta | clock_on | final_clock | final_frame
        frame_number | initial_clock | initial_frame

These keywords allow to use the values of the clock which have been set in the command line switch options (or INI-file). They represent float or integer values, read from the animation options. You cannot re-declare these identifiers.

`clock`
The built-in float identifier `clock` is used to control animations in POV-Ray. Unlike some animation packages, the action in POV-Ray animated scenes does not depend upon the integer frame numbers. Rather you should design your scenes based upon the float identifier `clock`. For non-animated scenes its default value is 0 but you can set it to any float value using the INI file option `Clock=`n.n or the command-line switch `+K`n.n to pass a single float value your scene file.

Other INI options and switches may be used to animate scenes by automatically looping through the rendering of frames using various values for `clock`. By default, the clock value is 0 for the initial frame and 1 for the final frame. All other frames are interpolated between these values.
For example if your object is supposed to rotate one full turn over the course of the animation you could specify `rotate 360*clock*y`. Then as clock runs from 0 to 1, the object rotates about the y-axis from 0 to 360 degrees.

Although the value of `clock` will change from frame-to-frame, it will never change throughout the parsing of a scene.

`clock_delta`
The built-in float identifier `clock_delta` returns the amount of time between clock values in animations in POV-Ray. While most animations only need the clock value itself, some animation calculations are easier if you know how long since the last frame. Caution must be used when designing such scenes. If you render a scene with too few frames, the results may be different than if you render with more frames in a given time period. On non-animated scenes, `clock_delta` defaults to 1.0. See section "Animation Options" for more details.

`clock_on`
With this identifier the status of the clock can be checked: 1 is on, 0 is off.

      #if(clock_on=0)
        //stuff for still image
      #else
        //some animation
      #end

`frame_number`
If you rather want to define the action in POV-Ray animated scenes depending upon the integer frame numbers, this identifier can be used.
It reads the number of the frame currently being rendered.

      #if(frame_number=1)
        //stuff for first image or frame
      #end
      #if(frame_number=2)
        //stuff for second image or frame
      #end
      #if(frame_number=n)
        //stuff for n th image or frame
      #end

`initial_clock`
This identifier reads the value set through the INI file option `Initial_Clock=`n.n or the command-line switch `+KI`n.n.

`final_clock`
This identifier reads the value set through the INI file option `Final_Clock=`n.n or the command-line switch `+KF`n.n.

`initial_frame`
This identifier reads the value set through the INI file option `Initial_Frame=`n or the command-line switch `+KFI`n.

`final_frame`
This identifier reads the value set through the INI file option `Final_Frame=`n or the command-line switch `+KFF`n.

Note: that these values are the ones actually used. When the option 'cyclic animation' is set, they could be different from the ones originally set in the options.

Image-size are:

    FLOAT_BUILT-IN_IDENT:
         image_width | image_height

`image_width`
This identifier reads the value set through the INI file option `Width=`n or the command-line switch `+W`n.

`image_height`
This identifier reads the value set through the INI file option `Height=`n or the command-line switch `+H`n.

You could use these keywords to set the camera ratio (up and right vectors) correctly. The viewing angle of the camera covers the full width of the rendered image. The camera ratio will always follow the ratio of the image width to height, regardless of the set image size. Use it like this:

      up y*image_height
      right x*image_width

You could also make some items of the scene dependent on the image size:

      #if (image_width < 300) crand 0.1 #else crand 0.5 #end

    or:

      image_map {
        pattern image_width, image_width {  //make pattern resolution
          gradient x                        //dependent of render width
          color_map { [ 0.0 ... ] [ 1.0 ... ] }
        }
      }

Version is:

    FLOAT_BUILT-IN_IDENT:
         version

The built-in float variable `version` contains the current setting of the version compatibility option. Although this value defaults to the current POV-Ray version number, the initial value of `version` may be set by the INI file option `Version=`n.n or by the `+MV`n.n command-line switch. This tells POV-Ray to parse the scene file using syntax from an earlier version of POV-Ray.

The INI option or switch only affects the initial setting. Unlike other built-in identifiers, you may change the value of `version` throughout a scene file. You do not use `#declare` to change it though. The `#version` language directive is used to change modes. Such changes may occur several times within scene files.

Together with the built-in `version` identifier the `#version` directive allows you to save and restore the previous values of this compatibility setting. The new `#local` identifier option is especially useful here. For example suppose `mystuff.inc` is in version 1 format. At the top of the file you could put:

     #local Temp_Vers = version;  // Save previous value
     #version 1.0;                // Change to 1.0 mode
     ...                          // Version 1.0 stuff goes here...
     #version Temp_Vers;          // Restore previous version

Note: there should be a semi-colon after the float expression in a `#version` directive. If omitted, it generates a warning and some macros may not work properly.

#### 3.2.1.4 Vector Expressions

POV-Ray often requires you to specify a vector. A vector is a set of related float values. Vectors may be specified using literals, identifiers or functions which return vector values. You may also create very complex vector expressions from combinations of any of these using various familiar operators.

POV-Ray vectors may have from two to five components but the vast majority of vectors have three components. Unless specified otherwise, you should assume that the word "vector" means a three component vector. POV-Ray operates in a 3D x, y, z coordinate system and you will use three component vectors to specify x, y and z values. In some places POV-Ray needs only two coordinates. These are often specified by a 2D vector called an UV vector. Fractal objects use 4D vectors. Color expressions use 5D vectors but allow you to specify 3, 4 or 5 components and use default values for the unspecified components. Unless otherwise noted, all 2, 4 or 5 component vectors work just like 3D vectors but they have a different number of components.

The syntax for combining vector literals into vector expressions is almost identical to the rules for float expressions. In the syntax for vector expressions below, some of the syntax items are defined in the section for float expressions. See "Float Expressions" for those definitions. Detailed explanations of vector-specific issues are given in the following sub-sections.

    VECTOR:
        NUMERIC_TERM [SIGN NUMERIC_TERM]
    NUMERIC_TERM:
        NUMERIC_FACTOR [MULT NUMERIC_FACTOR]
    NUMERIC_FACTOR:
        VECTOR_LITERAL        |
        VECTOR_IDENTIFIER     |
        SIGN NUMERIC_FACTOR   |
        VECTOR_FUNCTION       |
        VECTOR_BUILT-IN_IDENT |
        ( FULL_EXPRESSION )   |
        ! NUMERIC_FACTOR      |
        FLOAT
    VECTOR_LITERAL:
        < FLOAT , FLOAT , FLOAT >
    VECTOR_FUNCTION:
        min_extent ( OBJECT_IDENTIFIER )         |
        max_extent ( OBJECT_IDENTIFIER )         |
        trace(OBJECT_IDENTIFIER, VECTOR, VECTOR, [VECTOR_IDENTIFIER] )|
        vaxis_rotate( VECTOR , VECTOR , FLOAT )  |
        vcross( VECTOR , VECTOR )                |
        vrotate( VECTOR , VECTOR )               |
        vnormalize( VECTOR )                     |
        vturbulence(FLOAT, FLOAT, FLOAT, VECTOR)
    VECTOR_BUILT-IN_IDENT:
         x | y | z | t | u | v

Note: VECTOR_IDENTIFIERS are identifiers previously declared to have vector values.

##### 3.2.1.4.1 Literals

Vector literals consist of two to five float expressions that are bracketed by angle brackets `<` and `>`. The terms are separated by commas. For example here is a typical three component vector:

     < 1.0, 3.2, -5.4578 >

The commas between components are necessary to keep the program from thinking that the 2nd term is the single float expression `3.2-5.4578` and that there is no 3rd term. If you see an error message such as "Float expected but '>' found instead" then you probably have missed a comma.

Sometimes POV-Ray requires you to specify floats and vectors side-by-side. The rules for vector expressions allow for mixing of vectors with vectors or vectors with floats so commas are required separators whenever an ambiguity might arise. For example `<1,2,3>-4` evaluates as a mixed float and vector expression where 4 is subtracted from each component resulting in `<-3,-2,-1>`. However the comma in `<1,2,3>,-4` means this is a vector followed by a float.

Each component may be a full float expression. For example

     <This+3,That/3,5*Other_Thing>

is a valid vector.

##### 3.2.1.4.2 Identifiers

Vector identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows.

    VECTOR_DECLARATION:
        #declare IDENTIFIER = EXPRESSION; |
        #local IDENTIFIER = EXPRESSION;

Where IDENTIFIER is the name of the identifier up to 40 characters long and EXPRESSION is any valid expression which evaluates to a vector value.

Note: there should be a semi-colon after the expression in a vector declaration. If omitted, it generates a warning and some macros may not work properly. See " #declare vs. #local" for information on identifier scope.

Here are some examples....

     #declare Here = <1,2,3>;
     #declare There = <3,4,5>;
     #declare Jump = <Foo*2,Bar-1,Bob/3>;
     #declare Route = There-Here;
     #declare Jump = Jump+<1,2,3>;

Note: you invoke a vector identifier by using its name without any angle brackets. As the last example shows, you can re-declare a vector identifier and may use previously declared values in that re-declaration. There are several built-in identifiers which POV-Ray declares for you. See section "Built-in Vector Identifiers" for details.

##### 3.2.1.4.3 Operators

Vector literals, identifiers and functions may also be combined in expressions the same as float values. Operations are performed on a component-by-component basis. For example `<1,2,3> + <4,5,6>` evaluates the same as `<1+4,2+5,3+6>` or `<5,7,9>`. Other operations are done on a similar component-by-component basis. For example `(<1,2,3> = <3,2,1>)` evaluates to `<0,1,0>` because the middle components are equal but the others are not. Admittedly this is not very useful but it is consistent with other vector operations.

Conditional expressions such as `(C ? A : B)` require that `C` is a float expression but `A` and `B` may be vector expressions. The result is that the entire conditional evaluates as a valid vector. For example if `Foo` and `Bar` are floats then `(Foo < Bar ? <1,2,3> : <5,6,7>)` evaluates as the vector `<1,2,3>` if `Foo` is less than `Bar` and evaluates as `<5,6,7>` otherwise.

You may use the dot operator to extract a single float component from a vector. Suppose the identifier `Spot` was previously defined as a vector. Then `Spot.x` is a float value that is the first component of this x, y, z vector. Similarly `Spot.y` and `Spot.z` reference the 2nd and 3rd components. If `Spot` was a two component UV vector you could use `Spot.u` and `Spot.v` to extract the first and second component. For a 4D vector use `.x`, `.y`, `.z`, and `.t` to extract each float component. The dot operator is also used in color expressions which are covered later.

##### 3.2.1.4.4 Operator Promotion

You may use a lone float expression to define a vector whose components are all the same. POV-Ray knows when it needs a vector of a particular type and will promote a float into a vector if need be. For example the POV-Ray `scale` statement requires a three component vector. If you specify `scale 5` then POV-Ray interprets this as `scale <5,5,5>` which means you want to scale by 5 in every direction.

Versions of POV-Ray prior to 3.0 only allowed such use of a float as a vector in various limited places such as `scale` and `turbulence`. However you may now use this trick anywhere. For example...

     box{0,1}  // Same as box{<0,0,0>,<1,1,1>}
     sphere{0,1} // Same as sphere{<0,0,0>,1}

When promoting a float into a vector of 2, 3, 4 or 5 components, all components are set to the float value, however when promoting a vector of a lower number of components into a higher order vector, all remaining components are set to zero. For example if POV-Ray expects a 4D vector and you specify `9` the result is `<9,9,9,9>` but if you specify `<7,6>` the result is `<7,6,0,0>`.

##### 3.2.1.4.5 Functions

POV-Ray defines a variety of built-in functions for manipulating floats, vectors and strings. Function calls consist of a keyword which specifies the name of the function followed by a parameter list enclosed in parentheses. Parameters are separated by commas. For example:

     keyword(param1,param2)

The following are the functions which return vector values. They take one or more float, integer, vector, or string parameters. Assume that `A` and `B` are any valid expression that evaluates to a vector; and `F` is any float expression.

`min_extent(OBJECT_IDENTIFIER), max_extent(OBJECT_IDENTIFIER)`. The `min_extent` and `max_extent` return the minimum and maximum coordinates of a #declared object's bounding box (Corner1 and Corner2), in effect allowing you to find the dimensions and location of the object.

Note: this is not perfect, in some cases (such as CSG intersections and differences or isosurfaces) the bounding box does not represent the actual dimensions of the object.

Example:

    #declare Sphere =
    sphere {
      <0,0,0>, 1
      pigment { rgb <1,0,0> }
    }
    #declare Min = min_extent ( Sphere );
    #declare Max = max_extent ( Sphere );
    object { Sphere }
    box {
        Min, Max
        pigment { rgbf <1,1,1,0.5> }
    }

`trace(OBJECT_IDENTIFIER, A, B, [VECTOR_IDENTIFIER])`. `trace` helps you finding the exact location of a ray intersecting with an object's surface. It traces a ray beginning at the point `A` in the direction specified by the vector `B`. If the ray hits the specified object, this function returns the coordinate where the ray intersected the object. If not, it returns `<0,0,0>`. If a fourth parameter in the form of a vector identifier is provided, the normal of the object at the intersection point (not including any normal perturbations due to textures) is stored into that vector. If no intersection was found, the normal vector is reset to `<0,0,0>`.

Note: Checking the normal vector for `<0,0,0>` is the only reliable way to determine whether an intersection has actually occurred, intersections can and do occur anywhere, including at `<0,0,0>`.

Example:

    #declare MySphere = sphere { <0, 0, 0>, 1 }
    #declare Norm = <0, 0, 0>;
    #declare Start = <1, 1, 1>;
    #declare Inter=
      trace ( MySphere, Start, <0, 0, 0>-Start, Norm );
      object {
        MySphere
        texture {
          pigment { rgb 1}
        }
      }
      #if (vlength(Norm)!=0)
      cylinder {
        Inter, Inter+Norm, .1
        texture {
          pigment {color red 1}
        }
      }
     #end

`vaxis_rotate(A,B,F)` Rotate `A` about `B` by `F`. Given the x,y,z coordinates of a point in space designated by the vector `A`, rotate that point about an arbitrary axis defined by the vector `B`. Rotate it through an angle specified in degrees by the float value `F`. The result is a vector containing the new x,y,z coordinates of the point.

`vcross(A,B)` Cross product of `A` and `B`. Returns a vector that is the vector cross product of the two vectors. The resulting vector is perpendicular to the two original vectors and its length is equal to the area of the parallelogram defined by them. Or to put in an other way, the cross product can also be formulated as:`AxB = |A| * |B| * sin(angle(A,B)) * perpendicular_unit_vector(A,B)` So the length of the resulting vector is proportional to the sine of the angle between `A` and `B`. See the animated demo scene `VECT2.POV` for an illustration.

`vnormalize(A)` Normalize vector `A`. Returns a unit length vector that is the same direction as `A`. Formula is vnormalize(A)=A/vlength(A).

Note: `vnormalize(<0,0,0>)` will result in an error.

`vrotate(A,B)` Rotate `A` about origin by `B`. Given the x,y,z coordinates of a point in space designated by the vector `A`, rotate that point about the origin by an amount specified by the vector `B`. Rotate it about the x-axis by an angle specified in degrees by the float value `B.x`. Similarly `B.y` and `B.z` specify the amount to rotate in degrees about the y-axis and z-axis. The result is a vector containing the new x,y,z coordinates of the point.

`vturbulence(Lambda, Omega, Octaves, A)` Turbulence vector at A. Given the x,y,z coordinates of a point in space designated by the vector A, return the turbulence vector for that point based on the numbers given for Lambda, Omega and Octaves. For the meaning of the parameters, check out the Lambda, Omega and Octaves sections.
The amount of turbulence can be controlled by multiplying the turbulence vector by a multiple. The frequency at which the turbulence vector changes can be controlled by multiplying A with a multiple. The turbulence vector returned by the function can be added to the original point A to obtain a turbulated version of the point A. Example :
`#declare MyVector = MyVector + Amount * vturbulence(2, 0.5, 6, MyVector * Frequency);`

See section "Float Functions" for other functions which are somewhat vector-related but which return floats. In addition to the above built-in functions, you may also define your own functions using the `#macro` directive. See the section "User Defined Macros" for more details.

##### 3.2.1.4.6 Built-in Constants

There are several built-in vector identifiers. You can use them to specify values or to create expressions but you cannot re-declare them to change their values. They are:

    VECTOR_BUILT-IN_IDENT:
        x | y | z | t | u | v

All built-in vector identifiers never change value. They are defined as though the following lines were at the start of every scene.

     #declare x = <1, 0, 0>;
     #declare y = <0, 1, 0>;
     #declare z = <0, 0, 1>;
     #declare t = <0, 0, 0, 1>;
     #declare u = <1, 0>;
     #declare v = <0, 1>;

The built-in vector identifiers `x`, `y`, and `z` provide much greater readability for your scene files when used in vector expressions. For example....

     plane { y, 1}    // The normal vector is obviously "y".
     plane { <0,1,0>, 1} // This is harder to read.
     translate 5*x    // Move 5 units in the "x" direction.
     translate <5,0,0>  // This is less obvious.

An expression like `5*x` evaluates to `5*<1,0,0>` or `<5,0,0>`.

Similarly `u` and `v` may be used in 2D vectors. When using 4D vectors you should use `x`, `y`, `z`, and `t` and POV-Ray will promote `x`, `y`, and `z` to 4D when used where 4D is required.

#### 3.2.1.5 Specifying Colors

    COLOR:
        COLOR_BODY             |
        color COLOR_BODY       | (this means the keyword color or
        colour COLOR_BODY         colour may optionally precede
                                  any color specification)
    COLOR_BODY:
        COLOR_VECTOR           |
        COLOR_KEYWORD_GROUP    |
        COLOR_IDENTIFIER
    COLOR_VECTOR:
        rgb <3_Term_Vector>  |
        rgbf <4_Term_Vector> |
        rgbt <4_Term_Vector> |
        [ rgbft ] <5_Term_Vector>
    COLOR_KEYWORD_GROUP:
        [ COLOR_KEYWORD_ITEM ]...
    COLOR_KEYWORD_ITEM:
        COLOR_IDENTIFIER       |
        red Red_Amount         |
        blue Blue_Amount       |
        green Green_Amount     |
        filter Filter_Amount   |
        transmit Transmit_Amount

Note: COLOR_IDENTIFIERS are identifiers previously declared to have color values. The 3, 4, and 5 term vectors are usually vector literals but may be vector expressions or floats promoted to vectors. See "Operator Promotion" and the sections below.

POV-Ray often requires you to specify a color. Colors consist of five values or color components. The first three are called `red`, `green`, and `blue`. They specify the intensity of the primary colors red, green and blue using an additive color system like the one used by the red, green and blue color phosphors on a color monitor.

The 4th component, called `filter`, specifies the amount of filtered transparency of a substance. Some real-world examples of filtered transparency are stained glass windows or tinted cellophane. The light passing through such objects is tinted by the appropriate color as the material selectively absorbs some frequencies of light while allowing others to pass through. The color of the object is subtracted from the light passing through so this is called subtractive transparency.

The 5th component, called `transmit`, specifies the amount of non-filtered light that is transmitted through a surface. Some real-world examples of non-filtered transparency are thin see-through cloth, fine mesh netting and dust on a surface. In these examples, all frequencies of light are allowed to pass through tiny holes in the surface. Although the amount of light passing through is diminished, the color of the light passing through is unchanged.

The color of the object and the color transmitted through the object together contribute 100% of the final color. So if `transmit` is set to 0.9, the transmitted color contributes 90% and the color of the object contributes only 10%. This is also true outside of the 0-1 range, so for example if `transmit` is set to 1.7, the transmitted color contributes with 170% and the color of the object contributes with minus 70%. Using `transmit` values outside of the 0-1 range can be used to create interesting special effects, but does not correspond to any phenomena seen in the real world. An example:

    #version 3.5;
    global_settings {assumed_gamma 1.0}
    camera {location -2.5*z look_at 0 orthographic}
    box {
       0,1
       texture {
          pigment {
             gradient y
             colour_map {
                [0, red 1]
                [1, blue 1]
             }
          }
          finish{ambient 1}
       }
       texture {
          pigment {
             gradient x
             colour_map {
                [0, rgb 0.5 transmit -3]
                [1, rgb 0.5 transmit  3]
             }
          }
          finish{ambient 1}
       }
       translate <-0.5,-0.5,0>
       scale <3,2,1>
    }

When using the `transmit` value for special effects, you can visualize it this way: The `transmit` value means "contrast". 1.0 is no change in contrast, 0.5 is half contrast, 2.0 is double contrast and so on. You could say that `transmit` "scales" the colors. The color of the object is the "center value". All colors will get closer to the "center value" if `transmit` is between 0 and 1, and all colors will spread away from the "center value" if `transmit` is greater than 1. If `transmit` is negative the colors will be inverted around the "center value". Rgb 0.5 is common to use as "center value", but other values can be used for other effects. The "center value" really is a color, and non-gray colors can be used for interesting effects. The red, green and blue components are handled separately.

Note: early versions of POV-Ray used the keyword `alpha` to specify filtered transparency. However that word is often used to describe non-filtered transparency. For this reason `alpha` is no longer used.

Each of the five components of a color are float values which are normally in the range between 0.0 and 1.0. However any values, even negatives may be used.

Under most circumstances the keyword `color` is optional and may be omitted. We also support the British or Canadian spelling `colour`. Colors may be specified using vectors, keywords with floats or identifiers. You may also create very complex color expressions from combinations of any of these using various familiar operators. The syntax for specifying a color has evolved since POV-Ray was first released. We have maintained the original keyword-based syntax and added a short-cut vector notation. Either the old or new syntax is acceptable however the vector syntax is easier to use when creating color expressions.

The syntax for combining color literals into color expressions is almost identical to the rules for vector and float expressions. In the syntax for vector expressions, some of the syntax items are defined in the section for float expressions. See "Float Expressions" for those definitions. Detailed explanations of color-specific issues are given in the following sub-sections.

##### 3.2.1.5.1 Color Vectors

The syntax for a color vector is...

    COLOR_VECTOR:
        rgb <3_Term_Vector>   |
        rgbf <4_Term_Vector>  |
        rgbt <4_Term_Vector>  |
        [ rgbft ] <5_Term_Vector>

...where the vectors are any valid vector expressions of 3, 4 or 5 components. For example

     color rgb <1.0, 0.5, 0.2>

This specifies a color whose red component is 1.0 or 100% of full intensity. The green component is 0.5 or 50% of full intensity and the blue component is 0.2 or 20% of full intensity. Although the filter and transmit components are not explicitly specified, they exist and are set to their default values of 0 or no transparency.

The `rgbf` keyword requires a four component vector. The 4th component is the filter component and the transmit component defaults to zero. Similarly the `rgbt` keyword requires four components where the 4th value is moved to the 5th component which is transmit and then the filter component is set to zero.

The `rgbft` keyword allows you to specify all five components. Internally in expressions all five are always used.

Under some circumstances, if the vector expression is a 5 component expression or there is a color identifier in the expression then the `rgbtf` keyword is optional.

##### 3.2.1.5.2 Color Keywords

The older keyword method of specifying a color is still useful and many users prefer it.

    COLOR_KEYWORD_GROUP:
        [ COLOR_KEYWORD_ITEM ]...
    COLOR_KEYWORD_ITEM:
        COLOR_IDENTIFIER |
        red Red_Amount | blue Blue_Amount | green Green_Amount |
        filter Filter_Amount | transmit Transmit_Amount

Although the `color` keyword at the beginning is optional, it is more common to see it in this usage. This is followed by any of five additional keywords `red`, `green`, `blue`, `filter`, or `transmit`. Each of these component keywords is followed by a float expression. For example

     color red 1.0 green 0.5

This specifies a color whose red component is 1.0 or 100% of full intensity and the green component is 0.5 or 50% of full intensity. Although the blue, filter and transmit components are not explicitly specified, they exist and are set to their default values of 0. The component keywords may be given in any order and if any component is unspecified its value defaults to zero. A COLOR_IDENTIFIER can also be specified but it should always be first in the group. See "Common Color Pitfalls" for details.

##### 3.2.1.5.3 Color Identifiers

Color identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows.

    COLOR_DECLARATION:
        #declare IDENTIFIER = COLOR; |
        #local IDENTIFIER = COLOR;

Where IDENTIFIER is the name of the identifier up to 40 characters long and COLOR is any valid specification.

Note: there should be a semi-colon at the end of the declaration. If omitted, it generates a warning and some macros may not work properly. See " #declare vs. #local" for information on identifier scope.

Here are some examples....

     #declare White = rgb <1,1,1>;
     #declare Cyan = color blue 1.0 green 1.0;
     #declare Weird = rgb <Foo*2,Bar-1,Bob/3>;
     #declare LightGray = White*0.8;
     #declare LightCyan = Cyan red 0.6;

As the `LightGray` example shows you do not need any color keywords when creating color expressions based on previously declared colors. The last example shows you may use a color identifier with the keyword style syntax. Make sure that the identifier comes first before any other component keywords.

Like floats and vectors, you may re-define colors throughout a scene but the need to do so is rare.

##### 3.2.1.5.4 Color Operators

Color vectors may be combined in expressions the same as float or vector values. Operations are performed on a component by component basis. For example `rgb <1.0,0.5,0.2>*0.9` evaluates the same as `rgb<1.0,0.5,0.2>*<0.9,0.9,0.9>` or `rgb<0.9,0.45,0.18>`. Other operations are done on a similar component by component basis.

You may use the dot operator to extract a single component from a color. Suppose the identifier `Shade` was previously defined as a color. Then `Shade.red` is the float value of the red component of `Shade`. Similarly `Shade.green`, `Shade.blue`, `Shade.filter` and `Shade.transmit` extract the float value of the other color components. `shade.gray` returns the gray value of the color vector.

##### 3.2.1.5.5 Common Color Pitfalls

The variety and complexity of color specification methods can lead to some common mistakes. Here are some things to consider when specifying a color.

When using filter transparency, the colors which come through are multiplied by the primary color components. For example if gray light such as `rgb<0.9,0.9,0.9>` passes through a filter such as `rgbf<1.0,0.5,0.0,1.0>` the result is `rgb<0.9,0.45,0.0>` with the red let through 100%, the green cut in half from 0.9 to 0.45 and the blue totally blocked. Often users mistakenly specify a clear object by

     color filter 1.0

but this has implied red, green and blue values of zero. You have just specified a totally black filter so no light passes through. The correct way is either

     color red 1.0  green 1.0  blue 1.0  filter 1.0

or

     color transmit 1.0

In the 2nd example it does not matter what the rgb values are. All of the light passes through untouched. Another pitfall is the use of color identifiers and expressions with color keywords. For example...

     color My_Color red 0.5

this substitutes whatever was the red component of `My_Color` with a red component of 0.5 however...

     color My_Color + red 0.5

adds 0.5 to the red component of `My_Color` and even less obvious...

     color My_Color * red 0.5

that cuts the red component in half as you would expect but it also multiplies the green, blue, filter and transmit components by zero! The part of the expression after the multiply operator evaluates to `rgbft<0.5,0,0,0,0>` as a full 5 component color.

The following example results in no change to `My_Color`.

     color red 0.5 My_Color

This is because the identifier fully overwrites the previous value. When using identifiers with color keywords, the identifier should be first. Another issue to consider: some POV-Ray syntax allows full color specifications but only uses the rgb part. In these cases it is legal to use a float where a color is needed. For example:

     finish { ambient 1 }

The ambient keyword expects a color so the value `1` is promoted to `<1,1,1,1,1>` which is no problem. However

     pigment { color 0.4 }

is legal but it may or may not be what you intended. The `0.4` is promoted to `<0.4,0.4,0.4,0.4,0.4>` with the filter and transmit set to 0.4 as well. It is more likely you wanted...

     pigment { color rgb 0.4 }

in which case a 3 component vector is expected. Therefore the `0.4` is promoted to `<0.4,0.4,0.4,0.0,0.0>` with default zero for filter and transmit. Finally there is another problem which arises when using color dot operators in `#declare` or `#local` directives. Consider the directive:

     #declare MyColor = rgb <0.75, 0.5, 0.75>;
     #declare RedAmt = MyColor.red;

Now `RedAmt` should be a float but unfortunately it is a color. POV-Ray looks at the first keyword after the equals to try to guess what type of identifier you want. It sees the color identifier `MyColor` and assumes you want to declare a color. It then computes the float value as 0.75 then promotes that into `rgbft<0.75,0.75,0.75,0.75,0.75>`. It would take a major rewrite to fix this problem so we are just warning you about it. Any of the following work-arounds will work properly.

     #declare RedAmt = 0.0+MyColor.red;
     #declare RedAmt = 1.0*MyColor.red;
     #declare RedAmt = (MyColor.red);

#### 3.2.1.6 User-Defined Functions

Some objects allow you to specify functions that will be evaluated while rendering to determine the surface of these objects. In this respect functions are quite different to macros, which are evaluated at parse time but do not otherwise affect rendering. Additionally you may call these functions anywhere a Float Function is allowed, even during parsing. The syntax is identical to Float Expressions, however, only float functions that apply to float values may be used. Excluded are for example `strlen` or `vlength`. You find a full list of supported float functions in the syntax definition below.

    FLOAT:
        LOGIC_AND [OR LOGIC_AND]
    OR:
        |
    LOGIC_AND:
        REL_TERM [AND REL_TERM]
    AND:
        &
    REL_TERM:
        TERM [REL_OPERATOR TERM]
    REL_OPERATOR:
        < | <= | >= | > | = | !=
    TERM:
        FACTOR [SIGN FACTOR]
    SIGN:
        + | -
    FACTOR:
        MOD_EXPRESSION [MULT MOD_EXPRESSION]
    MULT:
        * | /
    EXPRESSION:
        FLOAT_LITERAL         |
        FLOAT_IDENTIFIER      |
        FLOAT_FUNCTION        |
        FLOAT_BUILT-IN_IDENT  |
        FUNCTION_IDENTIFIER   |
        ( FLOAT )             |
        IDENTIFIER            |
        SIGN EXPRESSION
    FLOAT_FUNCTION:
        abs( FLOAT ) | acos( FLOAT ) | acosh( FLOAT ) | asin( FLOAT ) |
        asinh( FLOAT ) | atan( FLOAT) | atanh( FLOAT) |
        atan2( FLOAT , FLOAT ) | ceil( FLOAT ) | cos( FLOAT ) |
        cosh( FLOAT ) | degrees( FLOAT ) | exp( FLOAT ) |
        floor( FLOAT ) | int( FLOAT ) | ln (Float) | log( FLOAT ) |
        max( FLOAT , FLOAT, ... ) | min( FLOAT , FLOAT, ... ) |
        mod( FLOAT , FLOAT ) | pow( FLOAT , FLOAT ) |
        radians( FLOAT ) | sin( FLOAT ) | sinh( FLOAT ) |
        sqrt( FLOAT ) | tan( FLOAT ) | tanh( FLOAT ) |
        select( FLOAT , FLOAT , FLOAT [, FLOAT] )
    FUNCTION_IDENTIFIER:
        #local FUNCTION_IDENTIFIER = function { FLOAT }               |
        #declare FUNCTION_IDENTIFIER = function { FLOAT }             |
        #local FUNCTION_IDENTIFIER = function(IDENT_LIST) { FLOAT }   |
        #declare FUNCTION_IDENTIFIER = function(IDENT_LIST) { FLOAT } |
        #local FUNCTION_IDENTIFIER = function{SPECIAL_FLOAT_FUNCTION} |
        #local VECTOR_IDENTIFIER = function{SPECIAL_VECTOR_FUNCTION}  |
        #local COLOR_IDENTIFIER = function { SPECIAL_COLOR_FUNCTION } |
    IDENT_LIST:
        IDENT_ITEM [, IDENT_LIST]
    IDENT_ITEM:
        x | y | z | u | v | IDENTIFIER
        (Note: x = u and y = v)
    SPECIAL_FLOAT_FUNCTION:
        pattern { PATTERN_BLOCK }
    SPECIAL_VECTOR_FUNCTION:
        TRANSFORMATION_BLOCK | SPLINE
    SPECIAL_COLOR_FUNCTION:
        PIGMENT
    PATTERN_BLOCK:
        PATTERN

Note: Only the above mentioned items can be used in user-defined functions. For example the rand() function is not available.

All of the above mentioned float functions are described in the section Float Functions.

##### 3.2.1.6.1 Sum and Product functions

`prod(i, b, n, a)` The product function.

`sum(i, b, n, a)` The sum function.

For both `prod` and `sum`: `i` is any variable name and `a` is any expression, usually depending on `i`. `b` and `n` are also any expression.
Example:

      #declare factorial = function(C) { prod(i, 1, C, i) }
      #declare A = factorial(5);

The first parameter is the name of the iteration variable. The second is the initial value expression and the third is the final value expression. Those may not depend on the iteration variable but the iteration variable may still be used inside those two expressions (because it happens to already have been defined) but its value is undefined. The last expression is the actual expression which will be iterated through. It may use any variable in scope.

The scope of an iteration variable is the sequence operation function. That is, a iteration variable is only defined when used inside the `sum/prod` function. Of course `sum/prod` functions may be nested. However, there is one limit of a maximum of 56 local variable defined simultaneously, which essentially means that in any combination `sum/prod` functions cannot be nested deeper than 56 levels.

The iteration variable is incremented by one for each step, but its initial and final value may be any value. The iteration will be continued as long as the iteration value is less or equal to the final value.

Note: because the iteration value is a floating-point variable, adding one will add a certain bias in a long iterations and thus the floating-point precision will be an issue in such a case and needs to be considered by allowing a reasonable error for the final value!

If the expression to be added has a negative sign it will of course in effect be substracted. Thus changing the sign will allow to generate negative values in the sum function. Equally multiplying by `1/expression` effectively creates a division when used in the prod function.

Obviously to work in the first place the initial value of the result is the neutral element of the operation. That is, a sum calculation starts with `0` and a product calculation starts with `1` just like it is assumed in the sum and product functions in 'regular' math.

It should be noted that mathematically either sum or product are redundant because:

        log10(prod(i, b, n, a)) = sum(i, b, n, log10(a))

which implies a sum can be represented as a product and vice versa, observing the usual mathematical constraints of logarithms, of course. However, as logarithms and their inverse (powers) are slow to compute both are provided...

##### 3.2.1.6.2 Functions and Macros

You can use macros in functions, but the macros will be called only once when the function is defined, not every time the function is called. You cannot pass function variables to the macros.

You can pass functions to macros, how to do this is best explained by an example:

      #macro Foo( Bar, X )
        #declare Y = Bar(X);
        #declare Z = Bar(Y);
      #end

      #declare FUNC=function(n){n+2}

      Foo(FUNC, 1)

      #debug str(Y,5,5)
      #debug "n"
      #debug str(Z,5,5)
      #debug "n"

##### 3.2.1.6.3 Declaring User-Defined Float Functions

You declare a user defined function using the `#declare` or `#local` directives. By default a function takes three parameters and you do not have to explicitly specify the parameter names. The default three parameters are `x`, `y` and `z`. For example:

     #declare foo = function { x + y * z }

If you need fewer or more parameters you have to explicitly specify the parameter list.

Note: `x` and `u` as well as `y` and `v` are equivalent so you may not specify both parameter names. You may not specify two or more parameters with the same name either. Doing so may result in a parse error or undefined function results.

The following are valid functions with parameters:

     #declare foo2 = function(x, y, z) { x + y * z }
     #declare foo3 = function(k1, k2, z, y) { x + y * z + k1 * y + k2 }
     #declare foo4 = function(h) { h * h + h }
     #declare foo4 = function(u, v) { x + y * v } //=u + v*v
     #declare foo4 = function(x, v, z) { u + y * v + z } //=x + v*v + z

Limits:

- The minimum number of parameters per function is 1.
- The maximum number of allowed parameters per function is 56.
- The maximum number of `function` blocks per scene is 1048575.
- The maximum number of operators per function is about 200000. Individual limits will be different depending on the types of operators used in the function.
- The maximum depth for nesting functions is 1024.
- The maximum number of constants in all functions 1048575.

Note: Redeclaring functions, directly, is not allowed. The way to do this is to `undef` it first.

There is one special float function type. You may declare a `pattern` function.

Note: the syntax is identical to that of patterns, however, you may not specify colors. Its result is always a float and not a color vector, as returned by a function containing a pigment.

     #declare foo = function {
       pattern {
         checker
       }
     }

Note: the number of parameters of special function types is determined automatically, so you do not need to specify parameter names.

##### 3.2.1.6.4 Declaring User-Defined Vector Functions

Right now you may only declare vector functions using one of the special function types. Supported types are `transform` and `spline` functions. For example:

     #declare foo = function {
       transform {
         rotate <90, 0, 0>
         scale 4
       }
     }

     #declare myvector = foo(4, 3, 7);

     #declare foo2 = function {
       spline {
         linear_spline
         0.0, <0,0,0>
         0.5, <1,0,0>
         1.0, <0,0,0>
       }
     }

     #declare myvector2 = foo2(0.7);

Function splines take the vector size into account. That is, a function containing a spline with five components will also return a five component vector (aka a color), a function containing a spline with two components will only return a two component vector and so on.

Note: the number of parameters of special function types is determined automatically, so you do not need to specify parameter names.

##### 3.2.1.6.5 Declaring User-Defined Color Functions

Right now you may only declare color functions using one of the special function types. The only supported type is the `pigment` function. You may use every valid `pigment`. This is a very simple example:

     #declare foo = function {
       pigment {
         color red 1
       }
     }

     #declare Vec = foo(1,2,3)

An example using a pattern:

     #declare foo = function {
       pigment {
         crackle
         color_map {
           [0.3, color Red]
           [1.0, color Blue]
         }
       }
     }

     #declare Val = foo(2,3,4).gray

Note: the number of parameters of special function types is determined automatically, so you do not need to specify parameter names.

##### 3.2.1.6.6 Internal Pre-Defined Functions

Several functions are pre-defined. These internal functions can be accessed through the "functions.inc", so it should be included in your scene.
The number of required parameters and what they control are also given in the include file, but the "functions.inc" chapter in the "Standard Include File" section gives more information.

#### 3.2.1.7 Strings

The POV-Ray language requires you to specify a string of characters to be used as a file name, text for messages or text for a text object. Strings may be specified using literals, identifiers or functions which return string values. See "String Functions" for details on string functions. Although you cannot build string expressions from symbolic operators such as are used with floats, vectors or colors, you may perform various string operations using string functions. Some applications of strings in POV-Ray allow for non-printing formatting characters such as newline or form-feed.

    STRING:
        STRING_FUNCTION   |
        STRING_IDENTIFIER |
    STRING_LITERAL STRING_LITERAL:
        "up to 256 ASCII characters"
    STRING_FUNCTION:
        str( FLOAT , INT , INT ) |
        concat( STRING , STRING , [STRING ,...]) | chr( INT ) |
        substr( STRING , INT , INT ) | strupr( STRING ) |
        strlwr( STRING ) | vstr( INT, VECTOR, STRING, INT, INT )

##### 3.2.1.7.1 String Literals

String literals begin with a double quote mark '"' which is followed by up to 256 characters and are terminated by another double quote mark. You can change the character set of strings using the `global_settings` `charset` option. The following are all valid string literals:

"Here" "There" "myfile.gif" "textures.inc"

Note: if you need to specify a quote mark in a string literal you must precede it with a backslash.

Example

     "Joe said \"Hello\" as he walked in."

is converted to

     Joe said "Hello" as he walked in.

If you need to specify a backslash, you will have to specify two. For example:

     "This is a backslash \\ and this is two \\\\"

Is converted to:

    This is a backslash \ and this is two \\

Windows users need to be especially wary about this as the backslash is also the windows path separator. For example, the following code does not produce the intended result:

      #declare DisplayFont = "c:\windows\fonts\lucon.ttf"
      text { ttf DisplayFont "Hello", 2,0 translate y*1.50 }

New users might expect this to create a text object using the font "c:\windows\fonts\lucon.ttf". Instead, it will give an error message saying that it cannot find the font file "c:windowsontslucon.ttf".

The correct form of the above code is as follows:

      #declare DisplayFont = "c:\\windows\\fonts\\lucon.ttf"
      text { ttf DisplayFont "Hello", 2,0 translate y*1.50 }

The escaping of backslashes occurs in all POV-Ray string literals. There are also other formatting codes such as `\n` for new line. See "Text Formatting" for details.

##### 3.2.1.7.2 String Identifiers

String identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows.

    STRING_DECLARATION:
        #declare IDENTIFIER = STRING |
        #local IDENTIFIER = STRING

Where IDENTIFIER is the name of the identifier up to 40 characters long and STRING is any valid string specification.

Note: unlike floats, vectors, or colors, there need not be a semi-colon at the end of the declaration. See "#declare vs. #local" for information on identifier scope.

Here are some examples...

     #declare Font_Name = "ariel.ttf"
     #declare Inc_File = "myfile.inc"
     #declare Name = "John"
     #declare Name = concat(Name," Doe")

As the last example shows, you can re-declare a string identifier and may use previously declared values in that re-declaration.

##### 3.2.1.7.3 String Functions

POV-Ray defines a variety of built-in functions for manipulating floats, vectors and strings. Function calls consist of a keyword which specifies the name of the function followed by a parameter list enclosed in parentheses. Parameters are separated by commas. For example:

     keyword(param1,param2)

The following are the functions which return string values. They take one or more float, integer, vector, or string parameters. Assume that `A` is any valid expression that evaluates to a float; `B`, `L`, and `P` are floats which are truncated to integers internally, `S`, `S1`, `S2` etc are strings.

`chr(B)` Character whose character value is `B`. Returns a single character string. The character value of the character is specified by an integer `B` which must be in the range 0 to 65535 if you specified `charset utf8` in the `global_settings` and 0 to 127 if you specified `charset ascii`. Refer to your platform specific documentation if you specified `charset sys`. For example `chr(70)` is the string "F". When rendering text objects you should be aware that the characters rendered are dependent on the (TTF) font being used.

`concat(S1,S2,...)` Concatenate strings `S1` and `S2`. Returns a string that is the concatenation of all parameter strings. Must have at least 2 parameters but may have more. For example:

     concat("Value is ", str(A,3,1), " inches")

If the float value `A` was `12.34321` the result is `"Value is 12.3 inches"` which is a string.

`str(A,L,P):` Convert float A to a formatted string. Returns a formatted string representation of float value `A`. The integer parameter `L` specifies the minimum length of the string and the type of left padding used if the string's representation is shorter than the minimum. If `L` is positive then the padding is with blanks. If `L` is negative then the padding is with zeros. The overall minimum length of the formatted string is abs(L). If the string needs to be longer, it will be made as long as necessary to represent the value.

The integer parameter `P` specifies the number of digits after the decimal point. If `P` is negative then a compiler-specific default precision is use. Here are some examples:

     str(123.456, 0, 3) "123.456"
     str(123.456, 4, 3) "123.456"
     str(123.456, 9, 3) "  123.456"
     str(123.456,-9, 3) "00123.456"

     str(123.456, 0, 2) "123.46"
     str(123.456, 0, 0) "123"
     str(123.456, 5, 0) "  123"
     str(123.000, 7, 2) " 123.00"

     str(123.456, 0,-1) "123.456000" (platform specific)

`strlwr(S)` Lower case of `S`. Returns a new string in which all upper case letters in the string S1 are converted to lower case. The original string is not affected. For example `strlwr("Hello There!")` results in "hello there!".

`substr(S,P,L)` Sub-string from `S`. Returns a string that is a subset of the characters in parameter `S` starting at the position specified by the integer value `P` for a length specified by the integer value `L`. For example `substr("ABCDEFGHI",4,2)` evaluates to the string "DE". If P+L-1>strlen(S) an error occurs.

`strupr(S)` Upper case of `S`. Returns a new string in which all lower case letters in the string `S` are converted to upper case. The original string is not affected. For example `strupr("Hello There!")` results in "HELLO THERE!".

`vstr(N,A,S,L,P)` Convert vector A to a formatted string. Returns a formatted string representation of vector `A` where the elements of the vector are separated by the string parameter `S`. The integer parameter `N` specifies the amount of dimensions in vector `A`. `N` is autoclipped to the range of 2 to 5, without warning. Specifying a vector `A` with more dimensions than given by `N` will result in an error.
The integer parameter `L` specifies the minimum length of the string and the type of left padding used if the string's representation is shorter than the minimum. The integer parameter `P` specifies the number of digits after the decimal point. If `P` is negative then a compiler-specific default precision is use. The function of `L` and `P` is the same as in `str`. Here are some examples:

     vstr(2, <1,2>, ", ", 0,1)         "1.0, 2.0"
     vstr(5, <1,2,3,4,5>, ", ", 0,1)   "1.0, 2.0, 3.0, 4.0, 5.0"
     vstr(1, 1, ", ", 0,1)             "1.0, 1.0"
     vstr(2, 1, ", ", 0,1)             "1.0, 1.0"
     vstr(5, 1, ", ", 0,1)             "1.0, 1.0, 1.0, 1.0, 1.0"
     vstr(7, 1, ", ", 0,1)             "1.0, 1.0, 1.0, 1.0, 1.0"
     vstr(3, <1,2>, ", ", 0,1)         "1.0, 2.0, 0.0"
     vstr(5, <1,2,3>, ", ", 0,1)       "1.0, 2.0, 3.0, 0.0, 0.0"
     vstr(3, <1,2,3,4>, ", ", 0,1)     error

See section "Float Functions" for other functions which are somewhat string-related but which return floats. In addition to the above built-in functions, you may also define your own functions using the `#macro` directive. See the section "User Defined Macros" for more details.

#### 3.2.1.8 Array Identifiers

You may declare arrays of identifiers of up to five dimensions. Any item that can be declared as an identifier can be declared in an array.

##### 3.2.1.8.1 Declaring Arrays

The syntax for declaring an array is as follows:

    ARRAY_DECLARATION:
      #declare IDENTIFIER = array[ INT ][[ INT ]]..[ARRAY_INITIALIZER] |
      #local IDENTIFIER = array[ INT ][[ INT ]]..[ARRAY_INITIALIZER]
    ARRAY_INITIALIZER:
      {ARRAY_ITEM, [ARRAY_ITEM, ]... }
    ARRAY_ITEM:
      RVALUE | ARRAY_INITIALIZER

Where IDENTIFIER is the name of the identifier up to 40 characters long and INT is a valid float expression which is internally truncated to an integer which specifies the size of the array. The optional ARRAY_INITIALIZER is discussed in the next section "Array Initializers". Here is an example of a one-dimensional, uninitialized array.

     #declare MyArray = array[10]

This declares an uninitialized array of ten elements. The elements are referenced as `MyArray[0]` through `MyArray[9]`. As yet, the type of the elements are undetermined. Once you have initialized any element of the array, all other elements can only be defined as that type. An attempt to reference an uninitialized element results in an error. For example:

     #declare MyArray = array[10]
     #declare MyArray[5] = pigment{White}     //all other elements must
                                              //be pigments too.
     #declare MyArray[2] = normal{bumps 0.2}  //generates an error
     #declare Thing = MyArray[4]   //error: uninitialized array element

Multi-dimensional arrays up to five dimensions may be declared. For example:

     #declare MyGrid = array[4][5]

declares a 20 element array of 4 rows and 5 columns. Elements are referenced from `MyGrid[0][0]` to `MyGrid[3][4]`. Although it is permissible to reference an entire array as a whole, you may not reference just one dimension of a multi-dimensional array. For example:

     #declare MyArray = array[10]
     #declare MyGrid = array[4][5]
     #declare YourArray = MyArray  //this is ok
     #declare YourGrid = MyGrid   //so is this
     #declare OneRow  = MyGrid[2] //this is illegal

The `#ifdef` and `#ifndef` directives can be used to check whether a specific element of an array has been declared. For methods to determine the size of an array look in the float section for `dimensions` and `dimension_size`

Large uninitialized arrays do not take much memory. Internally they are arrays of pointers so they probably use just 4 bytes per element. Once initialized with values, they consume memory depending on what you put in them.

The rules for local vs. global arrays are the same as any other identifier.

Note: this applies to the entire array. You cannot mix local and global elements in the same array. See "#declare vs. #local" for information on identifier scope.

##### 3.2.1.8.2 Array Initializers

Because it is cumbersome to individually initialize the elements of an array, you may initialize it as it is created using array initializer syntax. For example:

     #include "colors.inc"
     #declare FlagColors = array[3] {Red,White,Blue}

Multi-dimensional arrays may also be initialized this way. For example:

     #declare Digits =
     array[4][10]
     {
      {7,6,7,0,2,1,6,5,5,0},
      {1,2,3,4,5,6,7,8,9,0},
      {0,9,8,7,6,5,4,3,2,1},
      {1,1,2,2,3,3,4,4,5,5}
     }

The commas are required between elements and between dimensions as shown in the example.

#### 3.2.1.9 Spline Identifiers

Splines give you a way to define 'pathways' through your scenes. You specify a series of points, and POV-Ray interpolates to make a curve connecting them. Every point along the spline has a numerical value. A good example of a spline is the path of a moving object: the spline itself would be the path traced out by the object and the 'parameter' would be time; as time changes the object's position moves along the spline.
Therefore, given a time reference you could use this spline to find the position of the object. In fact, splines are very well suited to animation.

The syntax is:

    SPLINE_DECLARATION:
      #declare IDENTIFIER =
        spline {
          [SPLINE_IDENTIFIER] |
          [SPLINE_TYPE] |
          [Val_1, <Point_1>[,]
           Val_2, <Point_2>[,]
           ...
           Val_n, <Point_n>]
        }

    SPLINE_TYPE:
      linear_spline | quadratic_spline | cubic_spline | natural_spline

    SPLINE_USAGE:
      MySpline(Val) | MySpline(Val, SPLINE_TYPE)

The first item gives the type of interpolation.
In a `linear_spline`, straight lines connect each point.
In a `quadratic_spline`, a smooth curve defined by a second-order polynomial connects each point.
In `cubic_spline` and `natural_spline`, a smooth curve defined by a third-order polynomial connects each point.
The default is `linear_spline`.

Following this are a number of float values each followed by a position vector, all separated by commas. `Val_1`, `Val_2`, etc, are the value of the spline parameter at each specific point. The points need not be in order of their parameter values. If two points have the same parameter value, the second point will replace the first. Beyond the range of the lowest and highest parameter values, the spline position is fixed at the endpoints.

Note: Because of the way cubic_splines are defined: the first and last points are tangents rather than points on the spline, cubic_spline interpolation is only valid between the second and next-to-last points. For all other spline types, interpolation is valid from the first point to the last point. For t-values outside the valid range, POV-Ray returns the value of the nearest valid point.

To use a spline, you place the spline identifier followed by the parameter (in parentheses) wherever you would normally put a vector, similar to a macro. Splines behave mostly like three-dimensional vectors.
Here is an example:

    camera { location <0,2,-2> look_at 0 }
    light_source { <-5,30,-10> 1 }
    #declare MySpline =
      spline {
        cubic_spline
        -.25, <0,0,-1>
        0.00, <1,0,0>
        0.25, <0,0,1>
        0.50, <-1,0,0>
        0.75, <0,0,-1>
        1.00, <1,0,0>
        1.25, <0,0,1>
      }

    #declare ctr = 0;
    #while (ctr < 1)
      sphere {
        MySpline(ctr),.25
        pigment { rgb <1-ctr,ctr,0> }
      }
      #declare ctr = ctr + 0.01;
    #end

You can also have POV-Ray evaluate a spline as if it were a different type of spline by specifying the type of spline after the value to interpolate at, for example:

    sphere{ <2,0,2>, .25 pigment{rgb MySpline(clock, linear_spline)}}

Splines are 'intelligent' when it comes to returning vectors. The vector with the most components in the spline determines the size of the returned vector. This allows vectors from two to five components to be returned by splines.

Also, function splines take the vector size into account. That is, a function containing a spline with five components will also return a five component vector (aka a color), a function containing a spline with two components will only return a two component vector and so on.

##### 3.2.1.9.1 Splines and Macros

You can pass functions to macros, how to do this is best explained by an example

      #macro Foo( Bar, Val )
        #declare Y = Bar(Val).y;
      #end

      #declare myspline = spline {
          1, <4,5>
          3, <5,5>
          5, <6,5>
      }

      Foo(myspline, 2)

      #debug str(Y,5,5)
      #debug "\n"

More about "absorption"

- 3.6.2.1.1 Absorption in 3.6.2.1 Media Types
- 3.6.2.1.3 Scattering in 3.6.2.1 Media Types

More about "acos"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "ambient"

- 3.5.3 Finish in 3.5 Textures
- 3.5.3.1 Ambient in 3.5.3 Finish

More about "angle"

- 3.3.1.1.3 Angles in 3.3.1.1 Placing the Camera
- 3.7.9.2 Vector functions and macros in 3.7.9 math.inc

More about "array"

- 3.8.3.6 Arrays in 3.8.3 Language Basics
- 3.2.1.8 Array Identifiers in 3.2.1 Language Basics

More about "asin"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "atan"

- 3.4.1.6 Julia Fractal in 3.4.1 Finite Solid Primitives
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "atan2"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "autostop"

- 3.6.3.2.1 Photon Global Settings in 3.6.3.2 Using Photon Mapping in Your Scene
- 3.6.3.5.1 Autostop in 3.6.3.5 Advanced Techniques

More about "background"

- 3.3.2.2 Background in 3.3.2 Atmospheric Effects
- 3.8.12.1 Background in 3.8.12 Atmospheric Effects

More about "camera"

- 3.3.1 Camera in 3.3 Scene Settings
- 3.8.6 Camera in 3.8 Quick Reference

More about "color"

- 3.8.3.3 Colors in 3.8.3 Language Basics
- 3.2.1.5 Specifying Colors in 3.2.1 Language Basics

More about "cos"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "error_bound"

- 3.3.4.2.5 error_bound in 3.3.4.2 Adjusting Radiosity
- 3.3.4.2.11 nearest_count in 3.3.4.2 Adjusting Radiosity

More about "finish"

- 3.5.3 Finish in 3.5 Textures
- 3.8.10.6 Finish in 3.8.10 Texture

More about "fog"

- 3.3.2.3 Fog in 3.3.2 Atmospheric Effects
- 3.8.12.2 Fog in 3.8.12 Atmospheric Effects

More about "function"

- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions
- 3.2.1.4.5 Functions in 3.2.1.4 Vector Expressions
- 3.2.1.6 User-Defined Functions in 3.2.1 Language Basics

More about "global_settings"

- 3.3.3 Global Settings in 3.3 Scene Settings
- 3.8.13 Global Settings in 3.8 Quick Reference
- 2.3.10.4 Global settings in 2.3.10 SDL tutorial: A raytracer

More about "gradient"

- 3.5.11.17 Gradient in 3.5.11 Patterns
- 3.7.9.3 Vector Analysis in 3.7.9 math.inc

More about "interior"

- 3.6.1 Interior in 3.6 Interior & Media & Photons
- 3.8.9.3 Interior in 3.8.9 Object Modifiers

More about "interior_texture"

- 3.5.9 Interior Texture in 3.5 Textures
- 3.8.9.4 Interior Texture in 3.8.9 Object Modifiers

More about "ior"

- 3.6.1.4 Refraction in 3.6.1 Interior
- 3.7.4.6 IORs in 3.7.4 consts.inc

More about "isosurface"

- 3.4.4 Isosurface Object in 3.4 Objects
- 3.8.8.4 Isosurface in 3.8.8 Objects

More about "macro"

- 3.8.4.8 Macro in 3.8.4 Language Directives
- 3.2.2.8 User Defined Macros in 3.2.2 Language Directives

More about "material"

- 3.4.9.3 Material in 3.4.9 Object Modifiers
- 3.8.9.2 Material in 3.8.9 Object Modifiers

More about "matrix"

- 3.8.5 Transformations in 3.8 Quick Reference
- 2.2.7.1.4 Matrix in 2.2.7.1 Transformations

More about "max"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "media"

- 3.6.2 Media in 3.6 Interior & Media & Photons
- 3.8.11 Media in 3.8 Quick Reference

More about "mesh"

- 3.4.2.3 Mesh in 3.4.2 Finite Patch Primitives
- 3.4.2.4 Mesh2 in 3.4.2 Finite Patch Primitives

More about "min"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.7.9.2 Vector functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "noise_generator"

- 3.3.3.10 Noise_generator in 3.3.3 Global Settings
- 3.5.12 Pattern Modifiers in 3.5 Textures
- 3.5.12.4 Noise Generators in 3.5.12 Pattern Modifiers

More about "normal"

- 3.5.2 Normal in 3.5 Textures
- 3.8.10.5 Normal in 3.8.10 Texture
- 2.3.4.2 Normals in 2.3.4 Advanced Texture Options

More about "object"

- 3.4 Objects in 3 POV-Ray Reference
- 3.5.11.23 Object Pattern in 3.5.11 Patterns
- 3.8.8 Objects in 3.8 Quick Reference

More about "open"

- 3.6.1 Interior in 3.6 Interior & Media & Photons
- 3.2.2.3.1 The #fopen Directive in 3.2.2.3 File I/O Directives

More about "parametric"

- 3.4.5 Parametric Object in 3.4 Objects
- 3.8.8.5 Parametric in 3.8.8 Objects

More about "pattern"

- 3.5.11 Patterns in 3.5 Textures
- 3.8.10.7 Pattern in 3.8.10 Texture
- 3.2.1.6.3 Declaring User-Defined Float Functions in 3.2.1.6 User-Defined Functions

More about "photons"

- 3.6.3 Photons in 3.6 Interior & Media & Photons
- 3.6.3.2.1 Photon Global Settings in 3.6.3.2 Using Photon Mapping in Your Scene
- 3.8.13.2 Photons in 3.8.13 Global Settings

More about "pigment"

- 3.5.1 Pigment in 3.5 Textures
- 3.8.10.4 Pigment in 3.8.10 Texture
- 2.3.4.1 Pigments in 2.3.4 Advanced Texture Options

More about "pow"

- 3.7.9.2 Vector functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "radiosity"

- 3.3.4 Radiosity in 3.3 Scene Settings
- 3.8.13.1 Radiosity in 3.8.13 Global Settings
- 2.3.7 Radiosity in 2.3 Advanced Features

More about "rainbow"

- 3.3.2.5 Rainbow in 3.3.2 Atmospheric Effects
- 3.8.12.4 Rainbow in 3.8.12 Atmospheric Effects

More about "rand"

- 3.5.3.2.3 Crand Graininess in 3.5.3.2 Diffuse Reflection Items
- 3.7.11.1 Flat Distributions in 3.7.11 rand.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "refraction"

- 3.6.1.4 Refraction in 3.6.1 Interior
- 3.6.3.2.1 Photon Global Settings in 3.6.3.2 Using Photon Mapping in Your Scene

More about "rotate"

- 3.8.5 Transformations in 3.8 Quick Reference
- 2.2.7.1.3 Rotate in 2.2.7.1 Transformations
- 3.2.1.4.5 Functions in 3.2.1.4 Vector Expressions

More about "scale"

- 3.8.5 Transformations in 3.8 Quick Reference
- 2.2.7.1.2 Scale in 2.2.7.1 Transformations

More about "sin"

- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "sky_sphere"

- 3.3.2.4 Sky Sphere in 3.3.2 Atmospheric Effects
- 3.8.12.3 Sky Sphere in 3.8.12 Atmospheric Effects

More about "spline"

- 3.8.3.7 Splines in 3.8.3 Language Basics
- 3.2.1.9 Spline Identifiers in 3.2.1 Language Basics

More about "sqr"

- 3.4.1.6 Julia Fractal in 3.4.1 Finite Solid Primitives
- 3.7.9.2 Vector functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "tan"

- 3.4.1.6 Julia Fractal in 3.4.1 Finite Solid Primitives
- 3.7.9.1 Float functions and macros in 3.7.9 math.inc
- 3.2.1.3.4 Functions in 3.2.1.3 Float Expressions

More about "texture"

- 3.5 Textures in 3 POV-Ray Reference
- 3.8.10 Texture in 3.8 Quick Reference

More about "texture_list"

- 3.4.2.4 Mesh2 in 3.4.2 Finite Patch Primitives
- 3.5.8 Triangle Texture Interpolation in 3.5 Textures

More about "transform"

- 3.7.18 transforms.inc in 3.7 Include Files
- 3.8.5 Transformations in 3.8 Quick Reference

More about "translate"

- 3.8.5 Transformations in 3.8 Quick Reference
- 2.2.7.1.1 Translate in 2.2.7.1 Transformations

More about "turbulence"

- 3.5.12 Pattern Modifiers in 3.5 Textures
- 3.5.12.5 Turbulence in 3.5.12 Pattern Modifiers
- 3.2.1.4.5 Functions in 3.2.1.4 Vector Expressions

More about "uv_mapping"

- 3.5.7 UV Mapping in 3.5 Textures
- 3.8.9.1 UV Mapping in 3.8.9 Object Modifiers

More about "uv_vectors"

- 3.4.2.4 Mesh2 in 3.4.2 Finite Patch Primitives
- 3.5.7.2 UV Vectors in 3.5.7 UV Mapping

More about "warp"

- 3.5.12 Pattern Modifiers in 3.5 Textures
- 3.5.12.6 Warps in 3.5.12 Pattern Modifiers

More about "wood"

- 3.5.11.36 Wood in 3.5.11 Patterns
- 3.7.17.3 Woods in 3.7.17 textures.inc

More about "Strings"

- 3.8.3.5 Strings in 3.8.3 Language Basics
- 3.2.1.7 Strings in 3.2.1 Language Basics

More about "macros"

- 3.8.4.8 Macro in 3.8.4 Language Directives
- 3.2.2.8 User Defined Macros in 3.2.2 Language Directives

More about "#macro"

- 3.8.4.8 Macro in 3.8.4 Language Directives
- 3.2.2.8 User Defined Macros in 3.2.2 Language Directives