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:

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