⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diamond.c

📁 图形学课件 图形学课件 图形学课件
💻 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 + -