Context Free Art

Expressions

From Context Free Art

Jump to: navigation, search

Expressions

Context Free allows expressions to be used anywhere that the compiler accepts a number, except for rule/path weights and loop counts.

Because the cfdg syntax does not separate size or skew parameters with commas, expressions like 2 - 3 are ambiguous. Does size 2 - 3 mean size -1 or does it mean size 2 -3? To resolve this issue, expressions must be put in parentheses. The only exception to this rule is that single invocations of functions do not require parentheses. So, r (360/5) and x (sin(45) + cos(60)) require parentheses, but size sqrt(1/2) does not.

The following components are allowed in an expression:

Standard rules of operator ordering and precedence are supported; i.e., 2 + 3 * 4 is equivalent to 2 + (3 * 4). The list of supported functions are:

The rand_static() functions are converted into a random number when the cfdg file is compiled. So the value is constant for the entire run, but it is different for each variation. A rand_static() function inside of a loop has the same value for each iteration of the loop. This is not as useful as the full dynamic random function that everyone fervently desires. But it is the best that can be done with the Context Free 2.x execution model and it is moderately useful.

Let us know if there is a function that you would like to see added to Context Free.

startshape foo
 
path trill {
    MOVETO {x cos(234) y sin(234)}		// no parentheses required
    5* {r -144} 
        CURVETO {y 1 x1 (cos(234) + cos(324)) y1 (sin(234) + sin(324)) x2 1 y2 1}
        // parentheses required because of addition
    CLOSEPOLY {p align}
    FILL {p evenodd}
    STROKE {p buttjoin a -0.5}
}
 
rule foo {
    trill{}
}
Views
Personal tools
Navigation
Toolbox
MediaWiki
Attribution-Share Alike 2.5
book coverSee our new book:
Community of Variation