1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
5 // PerlMagick "piddle" demo re-implemented using Magick++ methods.
6 // The PerlMagick "piddle" demo is written by John Cristy
15 using namespace Magick;
17 int main( int /*argc*/, char ** argv)
20 // Initialize ImageMagick install location for Windows
21 InitializeMagick(*argv);
26 if(getenv("SRCDIR") != 0)
27 srcdir = getenv("SRCDIR");
30 // Create a 300x300 white canvas.
32 Image image( "300x300", "white" );
35 std::list<Magick::Drawable> drawList;
37 // Start drawing by pushing a drawing context with specified
39 drawList.push_back(DrawablePushGraphicContext());
40 drawList.push_back(DrawableViewbox(0,0,image.columns(),image.rows()));
45 drawList.push_back(DrawableStrokeColor("#ccf"));
46 for ( int i=0; i < 300; i += 10 )
48 drawList.push_back(DrawableLine(i,0, i,300));
49 drawList.push_back(DrawableLine(0,i, 300,i));
53 // Draw rounded rectangle.
55 drawList.push_back(DrawableFillColor("blue"));
56 drawList.push_back(DrawableStrokeColor("red"));
57 drawList.push_back(DrawableRoundRectangle(15,15, 70,70, 10,10));
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));
68 drawList.push_back(DrawableStrokeColor("black"));
69 drawList.push_back(DrawableStrokeWidth(4));
70 drawList.push_back(DrawableFillColor(Color()));
72 std::list<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));
83 drawList.push_back(DrawableStrokeColor("red"));
84 drawList.push_back(DrawableStrokeWidth(1));
85 drawList.push_back(DrawableLine(10,200, 20,190));
88 // Draw arc within a circle.
90 drawList.push_back(DrawableStrokeColor("black"));
91 drawList.push_back(DrawableFillColor("yellow"));
92 drawList.push_back(DrawableStrokeWidth(4));
93 drawList.push_back(DrawableCircle(160,70, 200,70));
95 drawList.push_back(DrawableStrokeColor("black"));
96 drawList.push_back(DrawableFillColor("blue"));
97 drawList.push_back(DrawableStrokeWidth(4));
99 std::list<VPath> path;
100 path.push_back(PathMovetoAbs(Coordinate(160,70)));
101 path.push_back(PathLinetoVerticalRel(-40));
102 path.push_back(PathArcRel(PathArcArgs(40,40, 0, 0, 0, -40,40)));
103 path.push_back(PathClosePath());
104 drawList.push_back(DrawablePath(path));
111 drawList.push_back(DrawableStrokeColor("red"));
112 drawList.push_back(DrawableFillColor("LimeGreen"));
113 drawList.push_back(DrawableStrokeWidth(3));
115 std::list<Magick::Coordinate> points;
116 points.push_back(Coordinate(160,120));
117 points.push_back(Coordinate(130,190));
118 points.push_back(Coordinate(210,145));
119 points.push_back(Coordinate(110,145));
120 points.push_back(Coordinate(190,190));
121 points.push_back(Coordinate(160,120));
122 drawList.push_back(DrawablePolygon(points));
128 drawList.push_back(DrawableStrokeWidth(5));
129 drawList.push_back(DrawableFillColor(Color())); // No fill
130 drawList.push_back(DrawableStrokeColor("yellow"));
131 drawList.push_back(DrawableLine(200,260, 200,200));
132 drawList.push_back(DrawableLine(200,200, 260,200));
133 drawList.push_back(DrawableStrokeColor("red"));
134 drawList.push_back(DrawableLine(260,200, 260,260));
135 drawList.push_back(DrawableStrokeColor("green"));
136 drawList.push_back(DrawableLine(200,260, 260,260));
141 drawList.push_back(DrawableFillColor("green"));
142 drawList.push_back(DrawableStrokeColor(Color())); // unset color
143 drawList.push_back(DrawablePointSize(24));
144 drawList.push_back(DrawableTranslation(30,140));
145 drawList.push_back(DrawableRotation(45.0));
146 drawList.push_back(DrawableText(0,0,"This is a test!"));
148 // Finish drawing by popping back to base context.
149 drawList.push_back(DrawablePopGraphicContext());
151 // Draw everything using completed drawing list
152 // image.debug(true);
153 image.draw(drawList);
155 // image.write( "piddle.mvg" );
157 cout << "Writing image \"piddle_out.miff\" ..." << endl;
159 image.compressType( RLECompression );
160 image.write( "piddle_out.miff" );
161 cout << "Writing MVG metafile \"piddle_out.mvg\" ..." << endl;
162 image.write( "piddle_out.mvg" );
164 // cout << "Display image..." << endl;
168 catch( exception &error_ )
170 cout << "Caught exception: " << error_.what() << endl;