// Shapes.cc
// Gloobs example program
//
// draws a few shapes, for no particular reason
//
// by Smylers
// 2000 Jan 10: original version
// 2000 Jan 17: improved comments
#include <gloobs.h>
int main()
{
// avoid having to use the Gloobs:: prefix all over the place by specifying
// the Gloobs namespace:
using namespace Gloobs;
// now can simply create a Canvas (meaning Gloobs::Canvas) of type X11
// (meaning Gloobs::X11):
Canvas DemoPic(X11, 400, 300, "Shapes");
// open rectangles can be created just like filled ones:
DemoPic.pen(4);
DemoPic.rectangle(25, 25, 275, 50);
// the line width is customizable:
DemoPic.pen(14);
DemoPic.set_line_width(4);
DemoPic.rectangle(300, 25, 375, 75);
// circles are easy, too; the first two parameters are the co-ordinates of
// the centre point, and the third one is the radius:
DemoPic.pen(11);
DemoPic.filled_circle(75, 225, 50);
// ellipses require two radii, one horizontal, and one vertical:
DemoPic.pen(2);
DemoPic.set_line_width(2);
DemoPic.ellipse(300, 250, 75, 25);
// an arc is a partial ellipse, so they have those same four parameters plus
// a start angle and an end angle; these are in degrees and measure
// counterclockwise from 3 o'clock:
DemoPic.pen(6);
DemoPic.arc(175, 250, 50, 25, 45, 160);
// a filled arc is like a pie segment; setting both the radii to the same
// value makes it a segment of a circle, rather than an ellipse:
DemoPic.pen(16);
DemoPic.filled_arc(150, 200, 50, 50, 0, 60);
// for more complex polygons, first create an array of the co-ordinates of
// their vertices:
double Steps[] =
{
25, 75,
25, 100,
50, 100,
50, 125,
75, 125,
75, 150,
100, 150,
100, 75
};
// then this can be drawn on the canvas; the first parameter is the number of
// vertices:
DemoPic.pen(22);
DemoPic.filled_polygon(8, Steps);
// individual pixels are plotted very simply:
DemoPic.pen(3);
DemoPic.plot(125, 75);
// quasi-pixels are like pixels, but bigger; they can be circular:
DemoPic.set_QP(6, QPcirc);
DemoPic.plot_QP(150, 75);
DemoPic.plot_QP(175, 75);
DemoPic.plot_QP(200, 75);
// or square:
DemoPic.set_QP(4, QPrect);
DemoPic.plot_QP(150, 100);
DemoPic.plot_QP(175, 100);
DemoPic.plot_QP(200, 100);
// for text, specify the co-ordinates of the bottom-left corner:
DemoPic.pen(19);
DemoPic.string(225, 200, "ameliorate");
// the font size is specified in pixels:
DemoPic.pen(20);
DemoPic.set_font_size(25);
DemoPic.string(150, 150, "synergy, not complexity");
DemoPic.pause();
return 0;
}