湖濱散記部落格的樹心幽徑[login][主頁]
364:20170708Koch-snowflake(three segment von koch curve)Last

alt

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <Magick++.h>
using namespace Magick;
void drawTen(int L,int ox,int oy, int w, int h,Image *pim){
if(L>0){
int ax,ay,bx,by,cx,cy,dx,dy,ex,ey;
int k=(L-1)/2;
int p5k=pow(5,k);
int wn,hn,wp,hp;
    if(L%2==1){
    wn=w/(7*p5k); wp=3*p5k*wn;
    hn=h/(7*p5k); hp=3*p5k*hn;
    ax=ox+2*p5k*wn; ay=oy+2*p5k*hn;
    bx=ox+1*p5k*wn; by=oy+0*p5k*hn;
    cx=ox+4*p5k*wn; cy=oy+1*p5k*hn;
    dx=ox+3*p5k*wn; dy=oy+4*p5k*hn;
    ex=ox+0*p5k*wn; ey=oy+3*p5k*hn;
    }
    else{
    wn=w/(15*p5k); wp=7*p5k*wn;
    hn=h/(15*p5k); hp=7*p5k*hn;
    ax=ox+4*p5k*wn; ay=oy+4*p5k*hn;
    bx=ox+0*p5k*wn; by=oy+1*p5k*hn;
    cx=ox+7*p5k*wn; cy=oy+0*p5k*hn;
    dx=ox+8*p5k*wn; dy=oy+7*p5k*hn;
    ex=ox+1*p5k*wn; ey=oy+8*p5k*hn;
    }
    drawTen(L-1,ax,ay,wp,hp,pim);
    drawTen(L-1,bx,by,wp,hp,pim);
    drawTen(L-1,cx,cy,wp,hp,pim);
    drawTen(L-1,dx,dy,wp,hp,pim);
    drawTen(L-1,ex,ey,wp,hp,pim);
}
if(L==0){
pim->strokeColor("white");
pim->draw(DrawableLine(ox+w/3,oy+0,ox+w/3,oy+h));
pim->draw(DrawableLine(ox+2*w/3,oy+0,ox+2*w/3,oy+h));
pim->draw(DrawableLine(ox+0,oy+h/3,ox+w,oy+h/3));
pim->draw(DrawableLine(ox+0,oy+2*h/3,ox+w,oy+2*h/3));
pim->draw(DrawableLine(ox,oy+h/3,ox,oy+2*h/3));
pim->draw(DrawableLine(ox+w-1,oy+h/3,ox+w-1,oy+2*h/3));
pim->draw(DrawableLine(ox+w/3,oy,ox+2*w/3,oy));
pim->draw(DrawableLine(ox+w/3,oy+h-1,ox+2*w/3,oy+h-1));
pim->strokeColor("red");
pim->draw(DrawableArc(ox+w/3+2,oy+h/3+2,ox+w*2/3-2,oy+h*2/3-2,0,360));
}
}

int main()
{
int w=3*7*5*10;
int h=3*7*5*10;
Image im( Geometry(w, h), Color("black"));
im.draw(DrawableStrokeColor(Color("black")));
im.strokeWidth(2);
drawTen(5,0,0,w,h,&im);
im.write("seg0708-5.jpg");
drawTen(4,0,0,w,h,&im);
im.write("seg0708-4.jpg");
drawTen(3,0,0,w,h,&im);
im.write("seg0708-3.jpg");
drawTen(2,0,0,w,h,&im);
im.write("seg0708-2.jpg");
drawTen(1,0,0,w,h,&im);
im.write("seg0708-1.jpg");
}

 


select id,article_id,topic,text from lt_articles_text where article_id =364; ok. update lt_articles set num_reads=num_reads +1 where id=364; ok.