海草
原理:分形之分叉结构 迭代法
绘图库:Easy Graphics Engine (EGE)
编程语言:c++
代码:
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <time.h>
const double pi = 3.1415926536;
struct Point
{
double x;
double y;
};
Point Rotate(Point p1, Point p2, double A)
{
Point r;
r.x = p1.x + (p2.x - p1.x) * cos(A) + (p2.y - p1.y) * sin(A);
r.y = p1.y + (p2.y - p1.y) * cos(A) - (p2.x - p1.x) * sin(A);
return r;
}
Point Zoom(Point p1, Point p2, double a)
{
Point r;
r.x = p1.x + (p2.x - p1.x) * a;
r.y = p1.y + (p2.y - p1.y) * a;
return r;
}
void D(Point p1, Point p2,double u,int n)
{
if(n>0)
{
Point p3,p4,p5,p6;
p3.x=p1.x+(p2.x-p1.x)/3;
p3.y=p1.y+(p2.y-p1.y)/3;
p4.x=p1.x+2*(p2.x-p1.x)/3;
p4.y=p1.y+2*(p2.y-p1.y)/3;
p5=Rotate(p3,p4,u*pi/180);
p6=Rotate(p4,p2,2*pi-u*pi/180);
line_f(p1.x,p1.y,p2.x,p2.y);
line_f(p3.x,p3.y,p5.x,p5.y);
line_f(p4.x,p4.y,p6.x,p6.y);
D(p1,p3,u,n-1);
D(p3,p4,u,n-1);
D(p4,p2,u,n-1);
D(p3,p5,u,n-1);
D(p4,p6,u,n-1);
}
}
int main()
{
double u,k;
struct Point p1,p2;
p1.x=400;
p1.y=570;
p2.x=400;
p2.y=50;
printf(" 蕨类\n");
cc:
printf("角度:\n");
scanf("%lf",&u);
printf("\n\n");
initgraph(800,600);
setcolor(RED);
D(p1,p2,u,10);
goto cc;
getch();
closegraph();
return 0;
}