sierpinski.cpp

来自「a source code for banker s algorithm」· C++ 代码 · 共 45 行

CPP
45
字号
#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 + =
减小字号Ctrl + -
显示快捷键?