Sometimes a picture is better than 10,000 words.
screenshot
P.S.
If anyone knows how to rotate the entire Cairo surface, please show me. $cr->rotate( PI/6 ); dosn't seem to work.
#!/usr/bin/perl
use strict;
use warnings;
use Cairo;
use constant {
IMG_WIDTH => 480,
IMG_HEIGHT => 480,
PI => 3.1416
};
die "png backend not supported" unless (Cairo::HAS_PNG_FUNCTIONS);
my $png = "$0.png";
my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT
+);
my $cr = Cairo::Context->create ($surf);
# to avoid a bit of angular confusion... :-)
# arc angles are measured from 0 on the x-axis, and angles are
# measured clockwise. So the usual 90 degree position is 3*PI/2.
# There is a negative arc function, see the perldoc for Cairo.
# In other words, the positive y axis is directed downward
#left
$cr->arc (IMG_WIDTH/2, IMG_HEIGHT/2, IMG_WIDTH/2, 3*PI/2, PI/2);
$cr->set_source_rgb (1, 1, 1);
$cr->fill;
#right
$cr->arc (IMG_WIDTH/2, IMG_HEIGHT/2, IMG_WIDTH/2, PI/2, 3*PI/2);
$cr->set_source_rgb (0, 0, 0);
$cr->fill;
#top semicircle
$cr->arc (IMG_WIDTH/2, 3*IMG_HEIGHT/4, IMG_HEIGHT/4, 3*PI/2, PI/2);
$cr->set_source_rgb (0, 0, 0);
$cr->fill;
#bottom semicircle
$cr->arc (IMG_WIDTH/2, IMG_HEIGHT/4, IMG_HEIGHT/4, PI/2 , 3*PI/2 );
$cr->set_source_rgb (1, 1, 1);
$cr->fill;
#encompassing boundary
$cr->arc (IMG_WIDTH/2, IMG_HEIGHT/2, IMG_WIDTH/2, 0, 2*PI);
$cr->set_source_rgb (1, 1, 1);
$cr->stroke;
# opposite kernels
# top
$cr->arc (IMG_WIDTH/2, IMG_HEIGHT/4, IMG_WIDTH/20, 0, 2*PI);
$cr->set_source_rgb (0, 0, 0);
$cr->fill;
#bottom
$cr->arc (IMG_WIDTH/2, 3*IMG_HEIGHT/4, IMG_HEIGHT/20, 0, 2*PI);
$cr->set_source_rgb (1, 1, 1);
$cr->fill;
$surf->write_to_png ($png);
system ("display $png"); # requires ImageMagick to be installed