Magick++: piddle.cpp Source File

Magick++ 7.0.10

piddle.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
4 //
5 // PerlMagick "piddle" demo re-implemented using Magick++ methods.
6 // The PerlMagick "piddle" demo is written by Cristy
7 //
8
9 #include <Magick++.h>
10 #include <string>
11 #include <iostream>
12
13 using namespace std;
14
15 using namespace Magick;
16
17 int main( int /*argc*/, char ** argv)
18 {
19
20 // Initialize ImageMagick install location for Windows
21 InitializeMagick(*argv);
22
23 try {
24
25 string srcdir("");
26 if(getenv("SRCDIR") != 0)
27 srcdir = getenv("SRCDIR");
28
29 //
30 // Create a 300x300 white canvas.
31 //
32 Image image( "300x300", "white" );
33
34 // Drawing list
35 std::vector<Magick::Drawable> drawList;
36
37 // Start drawing by pushing a drawing context with specified
38 // viewbox size
39 drawList.push_back(DrawablePushGraphicContext());
40 drawList.push_back(DrawableViewbox(0,0,image.columns(),image.rows()));
41
42 //
43 // Draw blue grid
44 //
45 drawList.push_back(DrawableStrokeColor("#ccf"));
46 for ( int i=0; i < 300; i += 10 )
47 {
48 drawList.push_back(DrawableLine(i,0, i,300));
49 drawList.push_back(DrawableLine(0,i, 300,i));
50 }
51
52 //
53 // Draw rounded rectangle.
54 //
55 drawList.push_back(DrawableFillColor("blue"));
56 drawList.push_back(DrawableStrokeColor("red"));
57 drawList.push_back(DrawableRoundRectangle(15,15, 70,70, 10,10));
58
59 drawList.push_back(DrawableFillColor("blue"));
60 drawList.push_back(DrawableStrokeColor("maroon"));
61 drawList.push_back(DrawableStrokeWidth(4));
62 drawList.push_back(DrawableRoundRectangle(15,15, 70,70, 10,10));
63
64 //
65 // Draw curve.
66 //
67 {
68 drawList.push_back(DrawableStrokeColor("black"));
69 drawList.push_back(DrawableStrokeWidth(4));
70 drawList.push_back(DrawableFillColor(Color()));
71
72 std::vector<Magick::Coordinate> points;
73 points.push_back(Coordinate(20,20));
74 points.push_back(Coordinate(100,50));
75 points.push_back(Coordinate(50,100));
76 points.push_back(Coordinate(160,160));
77 drawList.push_back(DrawableBezier(points));
78 }
79
80 //
81 // Draw line
82 //
83 {
84 const double dash_array[] = {4.0, 3.0, 0.0};
85 drawList.push_back(DrawableStrokeDashArray(dash_array));
86 drawList.push_back(DrawableStrokeColor("red"));
87 drawList.push_back(DrawableStrokeWidth(1));
88 drawList.push_back(DrawableLine(10,200, 54,182));
89 drawList.push_back(DrawableStrokeDashArray((double *) 0));
90 }
91
92 //
93 // Draw arc within a circle.
94 //
95 drawList.push_back(DrawableStrokeColor("black"));
96 drawList.push_back(DrawableFillColor("yellow"));
97 drawList.push_back(DrawableStrokeWidth(4));
98 drawList.push_back(DrawableCircle(160,70, 200,70));
99
100 drawList.push_back(DrawableStrokeColor("black"));
101 drawList.push_back(DrawableFillColor("blue"));
102 drawList.push_back(DrawableStrokeWidth(4));
103 {
104 std::vector<VPath> path;
105 path.push_back(PathMovetoAbs(Coordinate(160,70)));
106 path.push_back(PathLinetoVerticalRel(-40));
107 path.push_back(PathArcRel(PathArcArgs(40,40, 0, 0, 0, -40,40)));
108 path.push_back(PathClosePath());
109 drawList.push_back(DrawablePath(path));
110 }
111
112 //
113 // Draw pentogram.
114 //
115 {
116 drawList.push_back(DrawableStrokeColor("red"));
117 drawList.push_back(DrawableFillColor("LimeGreen"));
118 drawList.push_back(DrawableStrokeWidth(3));
119
120 std::vector<Magick::Coordinate> points;
121 points.push_back(Coordinate(160,120));
122 points.push_back(Coordinate(130,190));
123 points.push_back(Coordinate(210,145));
124 points.push_back(Coordinate(110,145));
125 points.push_back(Coordinate(190,190));
126 points.push_back(Coordinate(160,120));
127 drawList.push_back(DrawablePolygon(points));
128 }
129
130 //
131 // Draw rectangle.
132 //
133 drawList.push_back(DrawableStrokeWidth(5));
134 drawList.push_back(DrawableFillColor(Color())); // No fill
135 drawList.push_back(DrawableStrokeColor("yellow"));
136 drawList.push_back(DrawableLine(200,260, 200,200));
137 drawList.push_back(DrawableLine(200,200, 260,200));
138 drawList.push_back(DrawableStrokeColor("red"));
139 drawList.push_back(DrawableLine(260,200, 260,260));
140 drawList.push_back(DrawableStrokeColor("green"));
141 drawList.push_back(DrawableLine(200,260, 260,260));
142
143 //
144 // Draw text.
145 //
146 #if MAGICKCORE_FREETYPE_DELEGATE
147 if (getenv("MAGICK_FONT") != 0)
148 drawList.push_back(DrawableFont(string(getenv("MAGICK_FONT"))));
149 drawList.push_back(DrawableFillColor("green"));
150 drawList.push_back(DrawableStrokeColor(Color())); // unset color
151 drawList.push_back(DrawablePointSize(24));
152 drawList.push_back(DrawableTranslation(30,140));
153 drawList.push_back(DrawableRotation(45.0));
154 drawList.push_back(DrawableText(0,0,"This is a test!"));
155 #endif
156
157 // Finish drawing by popping back to base context.
158 drawList.push_back(DrawablePopGraphicContext());
159
160 // Draw everything using completed drawing list
161 // image.debug(true);
162 image.draw(drawList);
163
164 // image.write( "piddle.mvg" );
165
166 cout << "Writing image \"piddle_out.miff\" ..." << endl;
167 image.depth( 8 );
168 image.compressType( RLECompression );
169 image.write( "piddle_out.miff" );
170 cout << "Writing MVG metafile \"piddle_out.mvg\" ..." << endl;
171 image.write( "piddle_out.mvg" );
172
173 // cout << "Display image..." << endl;
174 // image.display( );
175
176 }
177 catch( exception &error_ )
178 {
179 cout << "Caught exception: " << error_.what() << endl;
180 return 1;
181 }
182
183 return 0;
184 }
Magick::Color
class MagickPPExport Color
Definition: Color.h:16
Magick::DrawableTranslation
Definition: Drawable.h:2249
main
int main(int, char **argv)
Definition: piddle.cpp:17
Magick::DrawablePointSize
Definition: Drawable.h:1242
Magick::DrawableFont
Definition: Drawable.h:1052
std
STL namespace.
Magick::Image::write
void write(Blob *blob_)
Definition: Image.cpp:4880
Magick::DrawableStrokeDashArray
Definition: Drawable.h:1719
Magick++.h
Magick::PathClosePath
Definition: Drawable.h:2515
Magick::DrawableLine
Definition: Drawable.h:1119
Magick::Coordinate
Definition: Drawable.h:46
Magick::PathArcArgs
Definition: Drawable.h:2354
Magick::DrawableText
Definition: Drawable.h:2000
Magick::Image::draw
void draw(const Drawable &drawable_)
Definition: Image.cpp:2785
Magick::DrawableFillColor
Definition: Drawable.h:934
Magick::DrawableRotation
Definition: Drawable.h:1462
Magick::DrawableCircle
Definition: Drawable.h:604
Magick::DrawablePath
Definition: Drawable.h:1182
Magick::DrawableBezier
Definition: Drawable.h:444
Magick::PathMovetoAbs
Definition: Drawable.h:3087
Magick::DrawableRoundRectangle
Definition: Drawable.h:1491
Magick::Image::rows
size_t rows(void) const
Definition: Image.cpp:1350
Magick::Image::columns
size_t columns(void) const
Definition: Image.cpp:588
Magick::DrawableStrokeWidth
Definition: Drawable.h:1971
Magick::DrawablePushGraphicContext
Definition: Drawable.h:1332
Magick
Definition: Blob.h:15
Magick::DrawablePopGraphicContext
Definition: Drawable.h:1311
Magick::DrawableStrokeColor
Definition: Drawable.h:1910
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:43
Magick::PathLinetoVerticalRel
Definition: Drawable.h:3057
Magick::PathArcRel
Definition: Drawable.h:2491
Magick::DrawablePolygon
Definition: Drawable.h:1271
Magick::Image::depth
void depth(const size_t depth_)
Definition: Image.cpp:691
Magick::Image
Definition: Image.h:53
Magick::DrawableViewbox
Definition: Drawable.h:2289
Magick::Image::compressType
void compressType(const CompressionType compressType_)
Definition: Image.cpp:628