-
Notifications
You must be signed in to change notification settings - Fork 33
Version 2 Syntax
There are a few syntax changes between version 2 and modern Context Free:
In Version 2.2 there are no shape parameters and the startshape can only contain a shape name, no shape adjustments are allowed. If you want the starting shape to have something other than the default state then you must create a setup rule that invokes your initial shape with shape adjustments.
Version 3
startshape sun[b 1 h 60 sat 1]
Version 2
startshape setup
rule setup {
sun {b 1 h 60 sat 1}
}
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:
Version 3
shape FLOWER {
CIRCLE [size 2]
loop 6 [r 60] LeftOrRightFlower [size 0.4 y 3]
}
Version 2
rule FLOWER {
CIRCLE {size 2}
6* {r 60} LeftOrRightFlower {size 0.4 y 3}
}
Multiple rule example:
Version 3
shape aShape
rule 0.5 {
SQUARE []
}
rule {
CIRCLE []
}
rule 2 {
TRIANGLE []
}
Version 2
rule aShape 0.5 {
SQUARE []
}
rule aShape {
CIRCLE []
}
rule aShape 2 {
TRIANGLE []
}
Basic shape adjustments in Context Free are surrounded by a single pair 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.
Version 3
shape spike {
SQUARE [b 1]
spike [[x 0.5 s 0.95 x 0.5]]
}
Version 2
rule spike { // Version 2
SQUARE {b 1}
spike [x 0.5 s 0.95 x 0.5]
}
Version 2 supports targeted color changes, like |hue 45 to change the hue target or sat 0.2| to do a targeted saturation change. The current color target is stored as part of the color state 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 persistent color target stored in the state.
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.
Version 2 had anonymous loops with integer constants for the loop count and it used a count* syntax for the loop header.
Version 3
shape FLOWER {
CIRCLE [size 2]
loop 6 [r 60] LeftOrRightFlower [size 0.4 y 3]
}
Version 2
rule FLOWER { // Version 2
CIRCLE {size 2}
6* {r 60} LeftOrRightFlower {size 0.4 y 3}
}
In Version 2, loops cannot be simple bodies of other loops. Only shape replacements, path operations, and path commands can be simple loop bodies.
Version 3
shape grid {
loop 10 [y 1]
loop 10 [x 1] shape []
}
Version 2
rule grid { // Version 2
10* {y 1} { // compound body because it is a loop
10* {x 1} shape {}
}
}
Version 3 uses the keyword import for importing cfdg files while version 2 uses the keyword include.
Version 3
import foo.cfdg
Version 2
include foo.cfdg
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)
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)
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.
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.