color assignment statement
The color assignment statement can take one of three forms:
The format of the indexed color assignment statement is:
set_color( double_expression );
set_color( double_expression, double_expression, double_expression );
set_color_hsv( double_expression, double_expression, double_expression );
In all cases, "double_expression" is a mathematical expression that evaluates to a number. Note that an expression that evaluates to a complex value is not acceptable - a more formal definition of double_expression can be found here but for now just remember that a double_expression evaluates to a number. Here is a simple example of an indexed color assignment:
set_color(2 * 50);
This example sets the current pixel to the rgb value associated with color table entry 100. A corresponding example for rgb color assignment would be:
set_color(255, 0, 0);
This example sets the current pixel to red. Some final notes on the two
Finally, here's what an hsv color assignment would look like:
set_color_hsv(1, 100, 200);Some final notes on the color assignment statements:
The general format of the double assignment statement is as follows:
This statement assigns the value of 'double_expression'
to the variable whose name is 'variable_name'. More precisely, the right
hand side of this assignment (double_expression) can
be composed of:
$a = $b = $c = 10.0;
The difference between '$a++' and '++$a' comes about when those
expressions are used as part of a longer assignment statement as
in:
In this example, after all the statments are execute both a, b and c will
be 2 but d would be 1. If the "++" or "--" comes after the variable the
variable is incremented (or decremented) but the original value is used
if this is part of a longer assignment statement
$a = 2;
Which means: "If $a is greater than $b assign $c the value 1 else
assign $c the value 2"
Additionally, a double expression can combine any of the items listed
above using:
Here are some examples of double variable assignment statements:
The format of the complex assignment statement is as follows:
Note that 'variable_name' is used, not '$variable_name'. The '$' is what
distinguishes a double variable from a complex variable. The preceding
statement assigns the value of 'complex_expression' to the complex variable
whose name is 'variable_name'. More precisely, the right hand side of
this assignment (complex_expression) can be composed of:
Additionally, a complex expression can combine any of the items listed
above using:
Here are some examples of complex variable assignment statements:
Conditional statements look like this:
If 'boolean_expression' evaluates to a non-zero value, the statements
inside that '{' '}' block are executed. If none of the boolean
expressions evaluates to true (and if there is an 'else' portion) the
statements inside the 'else' portion are executed. For a more precise
definition of boolean_expression see the discussion in the
next section.
It is important to note that statements here has the exact same
meaning as is did here. This means that you can
place any number of any type of statement inside your conditional statements.
The switch statement is similar to the if/elseif/else construct above.
Here is the general format:
The value supplied as 'switch(double_expression)' is first evaluated
and then compared to each value listed after the 'case' keywords.
If a match is found then the statements within the '{}' under
that case section are executed. If a match is found for a given
case section and that section has no 'break' after it then the
statements under the next case section will also be evaluated
and so on until a section followed by a 'break' is found.
Lastly, if no match is found within any of the 'case' sections and
if there is a 'default' section then the statements in the 'default'
section will be executed.
There are two situations where a boolean_expression is
used:
A boolean_expression will be one of:
Here are some examples of boolean_expressions:
The format of the for statement is as follows:
A statement_list is a comma separated list of set_color or
assignment statements. The for statement:
Here is an example
Note that the for statements' statement lists cannot contain conditional
statements (if/elseif/else) or other for statements. All other statement
types are allowed.
This statement can be used when you'd like to print out the values of
variables inside your formula file. The println statement is just like
the print statement except it automatically adds a newline to the
end of everything it prints.
The format of the print statement is:
If "filename" is supplied the output will be printed to the specified file.
If no "filename" is supplied the output will be written to the console
(which goes off into oblivion on win32 so use "filename" if you aren't
running on unix).
The print_statement_arguments are a set of items separated by '.'
characters. They can be literal strings, double expressions or
complex expressions.
Here are some examples:
These statements are only allowed inside a for statement or within the
while section of the formula file,
The break statement causes the termination of the for or while loop,
the continue statement causes the remainder of the statements within
the for or while loop to be skipped and control returns back to the
beginning of the loop.
Here are some examples:
Note that the 'break' or 'continue' only affects the inner most loop so
in this example:
double variable assignment statement
$variable_name = double_expression;
Example Explanation $a *= 2; $a = $a * 2 $a /= 3; $a = $a / 3 $a -= 4; $a = $a - 4 $a += 5; $a = $a + 5 $a++ $a = $a + 1 ++$a++ $a = $a + 1 $a-- $a = $a - 1 --$a++ $a = $a - 1
$a = 1;
$b = 1;
$c = ++$a;
$d = $b++;
$b = 3;
$c = ($a > $b ? 1 : 2);
real, imaginary, magnitude, sum_of_squares, degrees, radians
acsc, acsch, acos, acosh, acot, acoth, asec, asech, asin,
asinh, atan, atanh, ceil, cos, cosh, cot, coth, csc, csch, exp,
abs, fabs, fact, floor, log, log10, sec, sech, sin, sinh,
sqrt, tan, tanh, atan2, mod, fmod, pow, min, max, gamma,
get_sin_color, map_color
complex variable assignment statement
variable_name = complex_expression; or
variable_name = double_expression;
[ double_expression, double_expression ]
Anything that is a valid double_expression can be used to
construct a complex number in this fashion.
a = b = c;
z = y = $x;
conditional statement
if(boolean_expression)
{
zero or more statements
}
or
if(boolean_expression)
{
zero or more statements
}
elseif(boolean_expression)
{
zero or more statements
}
or
if(boolean_expression)
{
zero or more statements
}
else
{
zero or more statements
}
or
if(boolean_expression)
{
zero or more statements
}
elseif(boolean_expression)
{
zero or more statements
}
elseif(boolean_expression)
{
zero or more statements
}
else
{
zero or more statements
}
switch statement
switch(double_expression)
{
case double_expression:
{
zero_or_more_statements
}
case double_expression1: case double_expression2:
{
zero_or_more_statements
}
break;
default:
{
zero_or_more_statements
}
}
boolean_expression
for statement
for( statement_list ; boolean_expression; statement_list )
{
zero or more statements
}
$a = 0;
for($i = $j = 0; $i < 10; $i ++, $j ++)
{
$a = $i + $j;
}
print/println statement
print("filename", print_statement_arguments);
or
print(print_statement_arguments);
println("v1: " . $i * 6 . ", v2: " . sqrt($j) ^ 11);
print("Hello, World!\n"); // the '\n' appends a new line
println("temp.txt", "this is written to the temp.txt file");
break/continue statement
for($i = 0; $i < 10; $i ++)
{
if($i == 2) { break; }
println("i: " + $i);
}
println("done");
// The output from the above will be:
// i: 0
// i: 1
// done
for($i = 0; $i < 4; $i ++)
{
if($i == 2) { continue; }
println("i: " + $i);
}
println("done");
// The output from the above will be:
// i: 0
// i: 1
// i: 3
// done
for($i = 0; $i < 2; $i ++)
{
for($j = 0; $j < 2; $j ++)
{
if($j == 0) { break; }
}
}
The 'break' will terminate the inner loop but not the outer one.