// MultipleObjects.cc
// Gloobs example program
//
// demonstrates the use of multiple Gloobs objects, on multiple canvases
//
// by Smylers
// 2000 Jan 11
#include <gloobs.h>
int main()
{
using namespace Gloobs;
// define a canvas for the forest:
Canvas Forest(X11, 400, 300, "Forest");
int Ground = Forest.ink(0.5, 0.4, 0.4);
Forest.set_background(Ground);
// define a tree object:
int DarkTree = Forest.ink(0.2, 0.4, 0.2);
Object Tree;
Tree.push_back(new Triangle(DarkTree, Filled, 0, 12, 20, 40, 40, 12));
Tree.push_back(new Triangle(DarkTree, Filled, 4, 26, 20, 51, 36, 26));
Tree.push_back(new Triangle(DarkTree, Filled, 10, 42, 20, 60, 30, 42));
Tree.push_back(new Line(DarkTree, 3, 20, 0, 20, 12));
// draw a few:
Forest.draw_object(Tree, 30, 220, 1.0);
Forest.draw_object(Tree, 90, 240, 0.9);
Forest.draw_object(Tree, 160, 180, 1.7);
Forest.draw_object(Tree, 310, 150, 1.4);
Forest.draw_object(Tree, 50, 100, 1.5);
Forest.draw_object(Tree, 180, 60, 2.0);
// iterate through each primitive in the tree object, redefining the colour
// of each one:
int LightTree = Forest.ink(0.2, 0.6, 0.2);
for (Iter PrimNum = Tree.begin(); PrimNum != Tree.end(); PrimNum++)
(*PrimNum)->Pen = LightTree;
// now draw some of these trees in the new colour:
Forest.draw_object(Tree, 280, 200, 0.8);
Forest.draw_object(Tree, 230, 210, 1.2);
Forest.draw_object(Tree, 100, 160, 1.3);
Forest.draw_object(Tree, 120, 30, 2.2);
// define a house:
int Walls = Forest.ink(0.8, 0.9, 0.5);
int Roof = Forest.ink(0.7, 0.1, 0.1);
Object House;
House.push_back(new Rectangle(Walls, Filled, 8, 0, 32, 20));
House.push_back(new Triangle(Roof, Filled, 0, 20, 20, 35, 40, 20));
// draw a house in the forest:
Forest.draw_object(House, 250, 160);
// define a canvas for a Christmas tree:
Canvas Xmas(X11, 160, 240, "ChristmasTree");
int Bkgnd = Xmas.ink(0.9, 0.9, 0.0);
Xmas.set_background(Bkgnd);
// set the tree colour to something in this canvas:
int BrightTree = Xmas.ink(0.0, 0.7, 0.0);
for (Iter PrimNum = Tree.begin(); PrimNum != Tree.end(); PrimNum++)
(*PrimNum)->Pen = BrightTree;
// add a base as another primitive to the tree object:
int Base = Xmas.ink(0.9, 0.2, 0.0);
Tree.push_back(new Rectangle(Base, Filled, 12, 6, 28, -6));
// draw the tree on this second canvas:
Xmas.draw_object(Tree, 20, 40, 3);
// add a border directly to the canvas, not bothering with an object for it:
int Border = Xmas.ink(0.3, 0.6, 0.8);
Xmas.pen(Border);
Xmas.set_line_width(3);
Xmas.rectangle(5, 5, 155, 235);
Xmas.pause();
return 0;
}