Context Free Art

Expressions

From Context Free Art

Jump to: navigation, search

Contents

Ordinary Expressions

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

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).

Functions

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.

rand() and randint() return new values each time they are executed. randint() is equivalent to floor(rand()) and is provided as a convenience.

Special Functions

Let() Examples

shape test {
// let() returns a vector2, which is used in a size adjustment
CIRCLE[s let(n=5…6;m=7…8;n,m) a -0.5 sat 1 b 1 y 5 h 90]
 
// let() returns a shape adjustment, which is inserted into another shape adjustment
CIRCLE[trans let(n=5…6;m=7…8;[s n m x (2.5 + 0.5 * n)]) a -0.5 sat 1 b 1]
 
// Use lat to specify a shape and then draw with it
draw = let(n = randint(3); select(n, CIRCLE, SQUARE, TRIANGLE))
draw[s 5 7 a -0.5 sat 1 b 1 x -5 h 180]
 
// Directly use let() function as a shape specifier
let(n = randint(3); select(n, CIRCLE, SQUARE, TRIANGLE))[s 5 7 a -0.5 sat 1 b 1 y -5 h 270]
}


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

startshape foo
 
path trill {
MOVETO(cos(234), sin(234))
loop 5 [r -144]
CURVETO(0, 1, cos(234) + cos(324), sin(234) + sin(324), 1, 1)
CLOSEPOLY(CF::Align)
FILL(CF::EvenOdd)[]
STROKE[a -0.5]
}
 
shape foo {
trill[]
}

Simple Expressions

inside shape adjustments there are limitations placed on the types of expressions that are allowed. Expressions in shape adjustments are called simple expressions, while the full strength expressions described above are called ordinary expressions.

simple expression :==

You can get around this restriction by wrapping an ordinary expression in parentheses.

Views
Personal tools
Navigation
Toolbox
Powered by MediaWiki
Attribution-Share Alike 2.5
book coverSee our book:
Community of Variation