#include <windows.h>
#include <gl/gl.h>
#include <gl/glaux.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
//添加这3条语句
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")
#pragma comment (lib, "glaux.lib")
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) //这句是不让控制台窗体出现,如果想要出现,去掉即可。
void init()
{
glClearColor(0.0,0.0,0.0,1.0);//黑色背景
}
//绘制图形函数
float base = 2*3.14/5;
void start(float angle,float r,float g,float b,float R1,float R2,float x,float y)
{
glColor3f(r,g,b); //红色
glBegin(GL_LINE_LOOP);//线段
int i;
for(i=0;i<5;i++)
{
float a1 = cos(angle+base*i);
float a2 = sin(angle+base*i);
float b1 = cos(base/2.0+angle+base*i);
float b2 = sin(base/2.0+angle+base*i);
glVertex2f(x+R1*a1,y+R1*a2);
glVertex2f(x+R2*b1,y+R2*b2);
}
glEnd();
// glFinish();//强制之前的绘图函数执行
}
void CALLBACK draw()
{
glClear(GL_COLOR_BUFFER_BIT);
int j;
float angle = -1;
float r,g,b,R1,R2;
int x,y;
srand(time(NULL)); //srand(int)来设种子
for(j=0;j<10;j++)
{
int i;
i=rand()%400+1;/* i是[1,200]区间内的一个整数 */
x = i;
i=rand()%400+1;
y = i;
i=rand()%200;
r = i / 200.0f;
i=rand()%200;
g = i / 200.0f;
i=rand()%200;
b = i / 200.0f;
i=rand()%20;
R1 = i+ 40;
i=rand()%10;
R2 = i+ 10;
i=rand()%628;
angle = i/100.0;
// system("pause");
start(angle,r,g,b,R1,R2,x,y);
printf("%d,%d\n",x,y);
}
glFinish();
}
void CALLBACK change()
{
draw();
}
//主函数
void main()
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(100,100,500,500);
auxInitWindow("CGOpenGL");
init();
auxIdleFunc(change);//一定要在auxMainLoop前面
auxMainLoop(draw);
}
08-04
08-04
08-04
08-04
08-04
08-04
08-04
08-04
04-11