# Context Free Art – Tutorial 9

These exercises take a closer look at the colour information, hue, saturation and brightness.

```startshape Bryan

path Line {
MOVETO {x 0 y -9}
LINETO {x 0 y 9}
STROKE {sat 1 b 1}
}

rule Bryan {
360 * {x 0.05 h 1} Line {}
}```
```startshape Bryan

path Line {
MOVETO {x 0 y -9}
LINETO {x 0 y 9}
STROKE {h 200 sat 0 b 1}
}

rule Bryan {
400 * {x 0.05 sat 0.003} Line {}
}```

```startshape Bryan

path Line {
MOVETO {x 0 y -9}
LINETO {x 0 y 9}
STROKE {h 0 sat 1 b 0}
}

rule Bryan {
400 * {x 0.05 b 0.003} Line {}
}```
```startshape MyShape

rule MyLine {
TRIANGLE {s 0.016 1 sat 1 b 1}
}

rule MyShape {
360 * {r 1 h 1} MyLine {y -0.60}
}```

# Context Free Art – Tutorial 8

By using the same square, we further experiment with the various options in the STROKE command.

```STROKE {p miterjoin}

STROKE {p roundjoin}

STROKE {p beveljoin}```

```startshape MyShape

path Shape1 {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
STROKE {p buttcap}
}

path Shape2 {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
STROKE {p roundcap}
}

path Shape3 {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
STROKE {p squarecap}
}

rule MyShape {
Shape1 {x -1.5}
Shape2 {x 0}
Shape3 {x 1.5}
}```

# Context Free Art – Tutorial 7

We continue the study of path command. Take a look of the closed shape, a square.

```startshape MyShape

path Line {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
LINETO {x -0.5 y 0.5}
LINETO {x -0.5 y -0.5}
CLOSEPOLY {}
STROKE {}
}

rule MyShape {
Line {}
}```

If by any chances, you type the wrong position for the last end point or there is rounding error after a sequence of calculation, you may end of with:

```startshape MyShape

path Line {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
LINETO {x -0.5 y 0.5}
LINETO {x -0.45 y -0.45}
CLOSEPOLY {}
STROKE {}
}

rule MyShape {
Line {}
}```

Note the CLOSEPOLY command will connect an extra line segment to close the shape if there is a gap between the beginning and the end points. In case we want to get rid of the error, we can use the CLOSEPOLY command with an extra parameter align.

```startshape MyShape

path Line {
MOVETO {x -0.5 y -0.5}
LINETO {x 0.5 y -0.5}
LINETO {x 0.5 y 0.5}
LINETO {x -0.5 y 0.5}
LINETO {x -0.45 y -0.45}
CLOSEPOLY {p align}
STROKE {}
}

rule MyShape {
Line {}
}```

# Context Free Art – Tutorial 6

Today we start to think recursively. The following example uses a simple recursive definition of a SQUARE. In Context Free Art, we may not need to specify a stop condition when each iteration reduces its size, until eventually, the shape is too small to display.

```startshape Shape1

rule Shape3 {
SQUARE {a -0.9}
Shape3 {s 0.9 r 7}
}

rule Shape2 {
4 * {x 1} Shape3 {r 45}
}

rule Shape1 {
4 * {y 1} Shape2 {}
}
```

# Context Free Art – Tutorial 4

The following examples illustrate the use of repetition in Context Free Art.

```startshape MyShape

path Line1 {
MOVETO {x 0 y 0}
LINETO {x 1 y 0}
STROKE {width .01}
}

rule MyShape {
36 * {r 10} Line1 {}
}
```
```startshape MyShape

path Line1 {
MOVETO {x 0 y 0}
LINETO {x 1 y 0}
STROKE {width .01}
}

rule MyShape {
36 * {r 10 x 0.03} Line1 {}
}
```

# Context Free Art – Tutorial 3

These exercises cover the use of path in a shape.

```startshape MyShape

path Line1 {
MOVETO {x 0 y 0}
LINETO {x 1 y 1}
STROKE {width .01}
}

rule MyShape {
Line1 {}
}
```
```startshape MyShape

path Line1 {
MOVETO {x 0 y 0}
LINETO {x 1 y 1}
LINETO {x 0 y 1}
LINETO {x 1 y 0}
LINETO {x 0 y 0}
STROKE {width .01}
}

rule MyShape {
Line1 {}
}
```
```startshape MyShape

path Line1 {
MOVETO {x 0 y 0}
LINETO {x 1 y 0}
STROKE {width .01}
}

rule MyShape {
Line1 {r 25}
}
```

# Context Free Art – Tutorial 2

We introduce the use of the rotation parameter for a shape:

```startshape MyShape

rule MyShape {
SQUARE {x -4 r 90}
SQUARE {x -2 r 70}
SQUARE {r 50}
SQUARE {x +2 r 30}
SQUARE {x +4 r 10}
}```

```
Rotation

```

# Context Free Art – Tutorial 1

After we can create different primitive shapes, we start to combine them together. We cannot simply put all the primitive shapes within one single shape rule, like:

```startshape MyShape

rule MyShape {
CIRCLE {}
TRIANGLE {}
SQUARE {}
}```

Every shape command comes with parameters. We work with the translation parameters x and y to move the shape around in the canvas.

```startshape MyShape

rule MyShape {
CIRCLE {x -2}
TRIANGLE {}
SQUARE {x 2}
}```
```
Multiple shapes```
```startshape MyShape

rule MyShape {
CIRCLE {y 2}
TRIANGLE {}
SQUARE {y -2}
}```

```startshape MyShape

rule MyShape {
CIRCLE {x 2 y 2 size 0.8}
TRIANGLE {size 2}
SQUARE {x -2 y -2 size 0.5}
}```

```
Size variation```