标签:
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <GL/glut.h>
#include <math.h>
#include <time.h>
#include <cstdlib>
#include <Windows.h>
#define Pi 3.14
void Display(float x, float y, float R)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();//重置当前指定的矩阵为单位矩阵
gluOrtho2D(-300, 300, -300, 300);//参数分别代表(左下角x坐标,右上角x坐标,左下角y坐标,右上角y坐标)视图窗口
float r = R*sin(0.1*Pi) / sin(126.0 / 180.0*Pi);
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 1.0, 0);
for (int i = 0; i < 5; i++)
{
glVertex2d(R*cos(0.05 * 2 * Pi + 0.4*Pi*i) + x, R*sin(0.05 * 2 * Pi + 0.4*Pi*i) + y);
glVertex2d(r*cos(0.15 * 2 * Pi + 0.4*Pi*i) + x, r*sin(0.15 * 2 * Pi + 0.4*Pi*i) + y);
}
glEnd();
glFlush();
}
void Creat()
{
float x, y, r, g, b;
float R;
r = 1; g = 0; b = 0;
glClear(GL_COLOR_BUFFER_BIT);
srand(time(NULL));
for (int j = 0;; j++)
{
x = rand() % 600 - 300;
y = rand() % 600 - 300;
R = rand() % 100 - 50;
Display(x, y, R);
Sleep(50);
if(j>30){
glClear(GL_COLOR_BUFFER_BIT);
j=0;
}
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(600, 600);
glutCreateWindow("五角星");
glutDisplayFunc(&Creat);
glutMainLoop();
return 0;
}
标签:
原文地址:http://www.cnblogs.com/llforeverlove/p/5339879.html