gravity.cpp revision e3099b7aaccf9c581c3cf06c32738e214dba7a9c
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 <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") ); 42 base.depth(8); 43 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 ) ); 48 base.density( Geometry(72,72) ); 49 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} 84