Context Free Art

Version 2 Syntax

From Context Free Art

Jump to: navigation, search

Contents

Syntax Differences

There are a few syntax changes between version 2 and modern Context Free:

Rule Syntax

Context Free uses the shape token to introduce shape names and the rule token if a shape has more than one rule. Version 2 uses the rule token only and the shape's name must be repeated with each rule. Single rule example:

shape FLOWER {  // Version 3
CIRCLE [size 2]
loop 6 [r 60] LeftOrRightFlower [size 0.4 y 3]
}

vs.

rule FLOWER {  // Version 2
CIRCLE {size 2}
6* {r 60} LeftOrRightFlower {size 0.4 y 3}
}

Multiple rule example:

shape aShape  // Version 3
rule 0.5 {
SQUARE []
}
rule {
CIRCLE []
}
rule 2 {
TRIANGLE []
}

vs.

rule aShape 0.5 {  // Version 2
SQUARE []
}
rule aShape {
CIRCLE []
}
rule aShape 2 {
TRIANGLE []
}

Shape Adjustments

Basic shape adjustments in Context Free are surrounded by a single pait of square brackets: [adjustments]. Ordered shape adjustments have a doubled pair of square brackets: [[adjustments]]. In Version 2 curly brackets are used for basic shape adjustments and single square brackets are used for ordered shape adjustments.

shape spike {  // Version 3
SQUARE [b 1]
spike [[x 0.5 s 0.95 x 0.5]]
}

vs.

rule spike {  // Version 2
SQUARE {b 1}
spike [x 0.5 s 0.95 x 0.5]
}

Targeted Color Adjustments

Version 2 supports targeted color changes, like |hue 45 to change the target or sat 0.2| to do a targeted color change. The current color target is stored behind the scenes and used whenever there is a targeted color change. These color adjustment forms are not supported in version 3. Instead version 3 provides an alternate color targeting adjustment, like hue 0.05 60, in which the target and the adjustment are both provided and there is no color target remembered behind the scenes.

When converting version 2 color target code to version 3 there are two cases to consider. If the color target is set and never changed then it is simply a manner of moving the target from where it was set to where it is needed. If the color target changes then the designer must explicitly carry the target from shape to shape as a parameter.

Loops

Version 2 had anonymous loops with integer constants for the loop count and it used a count* syntax for the loop header.

shape FLOWER {  // Version 3
CIRCLE [size 2]
loop 6 [r 60] LeftOrRightFlower [size 0.4 y 3]
}

vs.

rule FLOWER {  // Version 2
CIRCLE {size 2}
6* {r 60} LeftOrRightFlower {size 0.4 y 3}
}

Simple vs. Compound Loop Bodies

In Version 2, loops cannot be simple bodies of other loops. Only shape replacements, path operations, and path commands can be simple loop bodies.

shape grid {    // Version 3
loop 10 [y 1]
loop 10 [x 1] shape []
}

vs.

rule grid {     // Version 2
10* {y 1} { // compound body because it is a loop
10* {x 1} shape {}
}
}

Importing CFDG Files

import foo.cfdg  // Version 3

vs.

include foo.cfdg  // Version 2

Configuration

Version 2 did not have configuration variables so it had specific directives for background color, tiling, and size.

//Version 3
CF::Background = [ b -1 ] // This changes the background to black
 
CF::Tile = [ s 3 4 ] // tile the design on a grid with spacing 3 units wide and 4 units high
CF::Size = [ s 3 4 x 1 y 2 ] // Size the canvas 3 units wide and 4 units high, centered on (-1, -2)

vs.

// Version 2
background { b -1 } // This changes the background to black
 
tile { s 3 4 } // tile the design on a grid with spacing 3 units wide and 4 units high
size { s 3 4 x 1 y 2} // Size the canvas 3 units wide and 4 units high, centered on (-1, -2)

Paths

There are too many differences in path syntax to enumerate here. They have the same drawing model, but Version 3 uses the new parameter syntax while Version 2 path syntax was a hack on top of the shape adjustment syntax. Compare the Version 3 path page to the Version 2 path page.

Conversion Tools

There is a simple script that translates version 2 cfdg files to version 3 syntax. Upload your cfdg file or directly enter the cfdg text into the web form. This translator cannot properly translate targeted color adjustments because the targeted color semantics changed between version 2 and version 3.

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