📄 sierpinski.cpp
字号:
#include<windows.h>
#include<gl.h>
#include<glut.h>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(5.0);
gluOrtho2D(0.0,100.0,0.0,100.0);
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
GLfloat Vertices[3][3]={{0.0,0.0,0.0},
{25.0,50.0,0.0},
{50.0,0.0,0.0},
};
GLfloat p[3]={7.5,5.0,0.0};
int rand();
int j,k;
glBegin(GL_POINTS);
glColor3f(3.0,0.0,0.0);
for(k=0;k<10000;k++)
{
j=rand()%3;
p[0]=(p[0]+Vertices[j][0])/2.0;
p[1]=(p[1]+Vertices[j][1])/2.0;
glVertex3fv(p);
}
glEnd();
glFlush();
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("sierspinski");
glutDisplayFunc(Display);
myInit();
glutMainLoop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -