?? diamond.c
字號:
/* gasket.c */
/* E. Angel, Interactive Computer Graphics */
/* A Top-Down Approach with OpenGL, Third Edition */
/* Addison-Wesley Longman, 2003 */
/* Two-Dimensional Sierpinski Gasket *//* Generated Using Randomly Selected Vertices *//* And Bisection */#include <GL/glut.h>#include "math.h"
#define PI 3.14159
#define NUMBER 8
#define RADIUS 400
//===================================================================void myinit(void){ /* attributes */ glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */ glColor3f(0.0, 0.0, 1.0); /* draw in red *//* set up viewing *//* 500 x 500 window with origin lower left */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-500.0, 500.0, -500.0, 500.0); glMatrixMode(GL_MODELVIEW);
glEnable(GL_COLOR_LOGIC_OP);}
//===================================================================void display( void ){
/* define a point data type */
typedef GLfloat point2[2];
point2 vertices[NUMBER];
int i,j;
glClear(GL_COLOR_BUFFER_BIT); /*clear the window */
for(i=0;i<NUMBER;i++)
{
vertices[i][0] = RADIUS*cos(PI/NUMBER+2*PI*i/NUMBER);
vertices[i][1] = RADIUS*sin(PI/NUMBER+2*PI*i/NUMBER);
}
for(i=0;i<NUMBER;i++)
for(j=i+1;j<NUMBER;j++)
{
glBegin(GL_LINES);
glVertex2fv(vertices[i]);
glVertex2fv(vertices[j]);
glEnd();
}
glFlush(); /* clear buffers */}
//===================================================================void main(int argc, char** argv){/* Standard GLUT initialization */ glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */ glutInitWindowSize(500,500); /* 500 x 500 pixel window */ glutInitWindowPosition(0,0); /* place window top left on display */ glutCreateWindow("Sierpinski Gasket"); /* window title */ glutDisplayFunc(display); /* display callback invoked when window opened */
myinit(); /* set attributes */ glutMainLoop(); /* enter event loop */}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -