樹心幽徑

« void utc2local(char *st1,char *st2,int dh) | Main | 20170619install_magicK (20171231setup revised) »

square.c
2017/06/19,13:55

alt

//treehrt@hrt:~/lake$ g++  `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7  square.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 innerRect(int L,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,Image *pim)
{
    printf("(%d,%d)- (%d,%d)-(%d,%d)-(%d,%d)-\n",x1,y1,x2,y2,x3,y3,x4,y4);
        int dx,dy;
        int ix1,ix2,ix3,ix4,iy1,iy2,iy3,iy4;

        dx=x2-x1;
        dy=y2-y1;
        ix1=x1+dx/4;iy1=y1+dy/4;

        dx=x3-x2;
        dy=y3-y2;
        ix2=x2+dx/4;iy2=y2+dy/4;

        dx=x4-x3;
        dy=y4-y3;
        ix3=x3+dx/4;iy3=y3+dy/4;

        dx=x1-x4;
        dy=y1-y4;
        ix4=x4+dx/4;iy4=y4+dy/4;

    pim->strokeColor("yellow"); 
    pim->draw(DrawableLine(ix1,iy1,ix2,iy2));

    pim->strokeColor("pink"); 
    pim->draw(DrawableLine(ix2,iy2,ix3,iy3));

    pim->strokeColor("blue"); 
    pim->draw(DrawableLine(ix3,iy3,ix4,iy4));

    pim->strokeColor("red"); 
    pim->draw(DrawableLine(ix4,iy4,ix1,iy1));
    if (L<18){
         innerRect(L+1,ix1,iy1,ix2,iy2,ix3,iy3,ix4,iy4,pim);
        }
}

int main()
{
int width=1024;
int height=768;

Image im( Geometry(width, height), Color("green"));
im.draw(DrawableStrokeColor(Color("black")));
im.strokeWidth(1);

int L=0;
innerRect(L,0,0,0,height,width,height,width,0,&im);

char st[60];
sprintf(st,"width=%d height=%d",width,height);
im.font("/usr/share/fonts/truetype/arphic/uming.ttc");
im.fontPointsize(32);
im.draw(DrawableText(32, 32, st));
im.write("square.jpg");
}

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType