以前写过的几段分型算法的代码,用来测试2d图形性能还不错

 
  
#include 
#include 

#include 
#include 

#define PI      3.141592654

void Koch(unsigned int h, int ax, int ay, int bx, int by, int c)
{
        int cx, cy, dx, dy, ex, ey;
        double l, alpha;

        if(((bx-ax)*(bx-ax)+(by-ay)*(by-ay)) 0)
        {
                x1=x+cos(alpha)*L;
        y1=y-sin(alpha)*L;
        gfx_lineto(h, x, y, x1, y1);
        alpha_L=alpha+PI/8;
        alpha_R=alpha-PI/8;
        L=2*L/3;
        Ramus(h, x1,y1,alpha_L,L,n-1);
        Ramus(h, x1,y1,alpha_R,L,n-1);
        }
}

#define B       (PI/6)
#define s1      2
#define s2      3
#define s3      1.4
void tree(unsigned int h, int x, int y, int L, float A, float C)
{
        int x1, y1, x2, y2, x1L, y1L, x2L, y2L, x1R, y1R, x2R, y2R;

        if(L>s1)
        {
                x2      =       x + cos(A) * L;
                y2      =       y - sin(A) * L;
                x2L     =       x2 + cos(A+B) * L / s2;
                y2L     =       y2 - sin(A+B) * L / s2;
                x2R     =       x2 + cos(A-B) * L / s2;
                y2R     =       y2 - sin(A-B) * L / s2;
                x1      =       x + cos(A) * L / s2;
                y1      =       y - sin(A) * L / s2;
                x1L     =       x1 + cos(A+B) * L / s2;
                y1L     =       y1 - sin(A+B) * L / s2;
                x1R     =       x1 + cos(A-B) * L / s2;
                y1R     =       y1 - sin(A-B) * L / s2;

                /*!~30%*/
                gfx_lineto(h, x, y, x2, y2);
                gfx_lineto(h, x2, y2, x2L, y2L);
                gfx_lineto(h, x2, y2, x2R, y2R);
                gfx_lineto(h, x1, y1, x1R, y1R);
                gfx_lineto(h, x1, y1, x1L, y1L);

                tree(h, x2, y2, L/s3, A-C, C);
                tree(h, x2L, y2L, L/s2, A+B, C);
                tree(h, x2R, y2R, L/s2, A-B, C);
                tree(h, x1R, y1R, L/s2, A-B, C);
                tree(h, x1L, y1L, L/s2, A+B, C);
        }
}


你可能感兴趣的:(Linux)