
//treehrt@hrt:~/lake$ g++ `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7 seg3.c `Magick++-config --ldflags --libs` -L/usr/local/zlib/lib -lz #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <Magick++.h> using namespace Magick; void draw3(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy,Image *pim){ pim->strokeColor("blue"); int px=(ax+bx)/2; int py=(ay+by)/2; pim->draw(DrawableLine(ax,ay,px,py));
pim->strokeColor("red"); int qx=(ax+cx)/2; int qy=(ay+cy)/2; pim->draw(DrawableLine(px,py,qx,qy));
pim->strokeColor("green"); int rx=(bx+cx)/2; int ry=(by+cy)/2; pim->draw(DrawableLine(qx,qy,rx,ry)); }
void drawA(int L,int ox,int oy,int w,int h,Image *pim) { draw3(ox+w*2/3,oy+h,ox,oy+h,ox,oy+h*1/3,ox+w*2/3,oy+h*1/3,pim); draw3(ox,oy+h*2/3,ox,oy,ox+w*2/3,oy,ox+w*2/3,oy+h*2/3,pim); draw3(ox+w*1/3,oy,ox+w,oy,ox+w,oy+h*2/3,ox+w*1/3,oy+h*2/3,pim); draw3(ox+w,oy+h*1/3,ox+w,oy+h,ox+w*1/3,oy+h,ox+w*1/3,oy+h*1/3,pim); if (L<3) { drawA(L+1,ox+w/3,oy,w/3,h/3,pim); drawA(L+1,ox,oy+h/3,w/3,h/3,pim); drawA(L+1,ox+w/3,oy+h*2/3,w/3,h/3,pim); drawA(L+1,ox+w*2/3,oy+h/3,w/3,h/3,pim); } }
int main() { int w=1024; int h=768;
Image im( Geometry(w, h), Color("black")); im.draw(DrawableStrokeColor(Color("black"))); im.strokeWidth(2); int L=0; drawA(L,0,0,w,h,&im); char st[60]; sprintf(st,"w=%d h=%d",w,h); im.font("/usr/share/fonts/truetype/arphic/uming.ttc"); im.fontPointsize(32); im.draw(DrawableText(32, 32, st)); im.write("seg3.jpg"); } |