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 {}
}
Hue information
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 {}
}
Saturation information

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 {}
}
Brightness information
startshape MyShape

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

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

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}
Different uses of join

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}
}
Different uses of cap

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 {}
}
CLOSEPOLY

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 {}
}
CLOSEPOLY error

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 {}
}

OpenCV C++ usage

I start using the C++ interface for OpenCV, instead of the old highgui C functions. Here is an example to do real time video capture from the default webcam.

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

using namespace cv;

int main(int, char**)
{
	VideoCapture cap(0);
	cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
	cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
	if (!cap.isOpened())
		return -1;

	namedWindow("camera",CV_WINDOW_AUTOSIZE);
	while (true)
	{
		Mat frame;
		cap >> frame;
		imshow("camera", frame);
		if (waitKey(10) >= 0)
			break;
	}
	return 0;
}