Magick++ 6.9.13
Loading...
Searching...
No Matches
gravity.cpp
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 <cstdlib>
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 const char *const p = getenv("MAGICK_FONT");
31 const string MAGICK_FONT(p ? p : "");
32
33 try {
34
35 string srcdir("");
36 if(getenv("SRCDIR") != 0)
37 srcdir = getenv("SRCDIR");
38
39 int x = 100;
40 int y = 100;
41
42 list<Image> animation;
43
44 Image base( Geometry(600,600), Color("white") );
45 base.depth(8);
46 base.strokeColor("#600");
47 base.fillColor(Color());
48 base.draw( DrawableLine( 300,100, 300,500 ) );
49 base.draw( DrawableLine( 100,300, 500,300 ) );
50 base.draw( DrawableRectangle( 100,100, 500,500 ) );
51 base.density( Geometry(72,72) );
52 base.strokeColor(Color());
53 base.fillColor("#600");
54 base.fontPointsize( 30 );
55 base.font( MAGICK_FONT );
56 base.boxColor( "red" );
57 base.animationDelay( 20 );
58 base.compressType( RLECompression );
59
60 for ( int angle = 0; angle < 360; angle += 30 )
61 {
62 cout << "angle " << angle << endl;
63 Image pic = base;
64 pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
65 pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
66 pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
67 pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
68 pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
69 pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
70 pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
71 pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
72 pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
73 animation.push_back( pic );
74 }
75 cout << "Writing image \"gravity_out.miff\" ..." << endl;
76 writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
77 // system( "animate gravity_out.miff" );
78
79 }
80 catch( exception &error_ )
81 {
82 cout << "Caught exception: " << error_.what() << endl;
83 return 1;
84 }
85
86 return 0;
87}