blob: cb18ef6cec637f55793ec856c80e7126e46a325f [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 2000, 2001, 2003
4//
5// Demo of text annotation with gravity. Produces an animation showing
cristybb503372010-05-27 20:51:26 +00006// the effect of rotated text assize_t with various gravity specifications.
cristy3ed852e2009-09-05 21:47:34 +00007//
8// After running demo program, run 'animate gravity_out.miff' if you
9// are using X-Windows to see an animated result.
10//
11// Concept and algorithms lifted from PerlMagick demo script written
cristye86f2f32014-01-08 17:30:27 +000012// by John Christy.
cristy3ed852e2009-09-05 21:47:34 +000013//
14
15#include <Magick++.h>
16#include <string>
17#include <iostream>
18#include <list>
19
20using namespace std;
21
22using namespace Magick;
23
24int main( int /*argc*/, char ** argv)
25{
26
27 // Initialize ImageMagick install location for Windows
28 InitializeMagick(*argv);
29
30 try {
31
32 string srcdir("");
33 if(getenv("SRCDIR") != 0)
34 srcdir = getenv("SRCDIR");
35
36 int x = 100;
37 int y = 100;
38
39 list<Image> animation;
40
41 Image base( Geometry(600,600), Color("white") );
cristy4a16cd52010-01-05 14:04:01 +000042 base.depth(8);
cristy3ed852e2009-09-05 21:47:34 +000043 base.strokeColor("#600");
44 base.fillColor(Color());
45 base.draw( DrawableLine( 300,100, 300,500 ) );
46 base.draw( DrawableLine( 100,300, 500,300 ) );
47 base.draw( DrawableRectangle( 100,100, 500,500 ) );
dirkbe1bbac2014-12-16 11:56:14 +000048 base.density( Point(72,72) );
cristy3ed852e2009-09-05 21:47:34 +000049 base.strokeColor(Color());
50 base.fillColor("#600");
51 base.fontPointsize( 30 );
52 base.boxColor( "red" );
53 base.animationDelay( 20 );
54 base.compressType( RLECompression );
55
56 for ( int angle = 0; angle < 360; angle += 30 )
57 {
58 cout << "angle " << angle << endl;
59 Image pic = base;
60 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
61 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
62 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
63 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
64 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
65 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
66 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
67 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
68 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
69 animation.push_back( pic );
70 }
71 cout << "Writing image \"gravity_out.miff\" ..." << endl;
72 writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
73 // system( "animate gravity_out.miff" );
74
75 }
76 catch( exception &error_ )
77 {
78 cout << "Caught exception: " << error_.what() << endl;
79 return 1;
80 }
81
82 return 0;
83}