gravity.cpp revision d9eec389c7cc5509499adbae12fd7a129914a732
1// 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 6// the effect of rotated text assize_t with various gravity specifications. 7// 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 12// by Cristy. 13// 14 15#include <cstring> 16#include <Magick++.h> 17#include <string> 18#include <iostream> 19#include <list> 20 21using namespace std; 22 23using namespace Magick; 24 25int main( int /*argc*/, char ** argv) 26{ 27 28 // Initialize ImageMagick install location for Windows 29 InitializeMagick(*argv); 30 31 try { 32 33 string srcdir(""); 34 if(getenv("SRCDIR") != 0) 35 srcdir = getenv("SRCDIR"); 36 37 int x = 100; 38 int y = 100; 39 40 list<Image> animation; 41 42 Image base( Geometry(600,600), Color("white") ); 43 base.depth(8); 44 base.strokeColor("#600"); 45 base.fillColor(Color()); 46 base.draw( DrawableLine( 300,100, 300,500 ) ); 47 base.draw( DrawableLine( 100,300, 500,300 ) ); 48 base.draw( DrawableRectangle( 100,100, 500,500 ) ); 49 base.density( Geometry(72,72) ); 50 base.strokeColor(Color()); 51 base.fillColor("#600"); 52 base.fontPointsize( 30 ); 53 base.boxColor( "red" ); 54 base.animationDelay( 20 ); 55 base.compressType( RLECompression ); 56 57 for ( int angle = 0; angle < 360; angle += 30 ) 58 { 59 cout << "angle " << angle << endl; 60 Image pic = base; 61 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle ); 62 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle ); 63 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle ); 64 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle ); 65 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle ); 66 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle ); 67 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle ); 68 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle ); 69 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle ); 70 animation.push_back( pic ); 71 } 72 cout << "Writing image \"gravity_out.miff\" ..." << endl; 73 writeImages( animation.begin(), animation.end(), "gravity_out.miff" ); 74 // system( "animate gravity_out.miff" ); 75 76 } 77 catch( exception &error_ ) 78 { 79 cout << "Caught exception: " << error_.what() << endl; 80 return 1; 81 } 82 83 return 0; 84} 85