注意事项:配置好OpenGL环境。
1.Cantor曲线:
//Cantor.h
#include <GL/glut.h>
#include <math.h>
#define PI 3.1415926
void Cantor(float ax, float ay ,float bx, float by ,float n, float d);
//Cantor.cpp
#include"Cantor.h"
/**ax,ay,bx,by 为直线段两端点坐标,n为迭代最小量,d为不同层次线之间距离**/
void Cantor(float ax, float ay ,float bx, float by ,float n, float d){
if( (bx - ax) < n)
return ;
else {
glBegin(GL_LINES);
glVertex2f(ax,ay);
glVertex2f(bx,by);
glEnd();
float cx,cy,dx,dy;
cx = ax + (bx - ax)/3;
cy = ay + d ;
dx = bx - (bx - ax)/3;
dy = by + d;
ay = ay + d;
by = by +d;
Cantor(ax,ay,cx,cy,n,d);
Cantor(dx,dy,bx,by,n,d);
}
}