前段时间老师布置一作业,我画了一个哆啦A梦,代码如下
#include <Windows.h>
#include <gl\glut.h>
#include <stdio.h>
#include<math.h>
#define GLUT_DISABLE_ATEXIT_HACK
#define N 100
const GLfloat tempR = 0.5f;//脸半径
const GLfloat PI = 3.1415926536f;
//颜色设置
static GLfloat ColorChoose[5][3] = {
{ 0.0, 0.74, 1.0 }, { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 },
{ 1.0, 1.0, 0.0 } };
static GLfloat r = 1.0f, g = 1.0f, b = 0.0f;
static GLfloat spin = 0.0;
int fg = 0;
static float x = 400, y = 400;
static int FACE_COLOR = 0;//湖蓝色
static int EYE_COLOR = 1;//白色
static int NOSE_COLOR = 2;//红色
static int LINE_COLOR = 3;//黑色
static int LINGDANG_COLOR = 4;//黄色
//画脸 0.0, 0.4, 0.4
void face(float x, float y, float radius)
{
int count;
int sections = 200;
GLfloat TWOPI = 2.0f * 3.14159f;
//glLineWidth(1.f);
glColor3f(ColorChoose[FACE_COLOR][0], ColorChoose[FACE_COLOR][1], ColorChoose[FACE_COLOR][2]);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
for (count = 0; count <= sections; count++)
{
glVertex2f(x + radius*cos(count*TWOPI / sections), y + radius*sin(count*TWOPI / sections));
}
glEnd();
}
//脸白
void face1(float x, float y, float radius)
{
int count;
int sections = 200;
GLfloat TWOPI = 2.0f * 3.14159f;
//glLineWidth(1.f);
glColor3f(ColorChoose[EYE_COLOR][0], ColorChoose[EYE_COLOR][1], ColorChoose[EYE_COLOR][2]);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
for (count = 0; count <= sections; count++)
{
glVertex2f(x + radius*cos(count*TWOPI / sections), y + radius*sin(count*TWOPI / sections));
}
glEnd();
}
//描线
void drawline(float x, float y, float radius)
{
int count;
int sections = 200;
GLfloat TWOPI = 2.0f * 3.14159f;
glLineWidth(3);
glColor3f(ColorChoose[LINE_COLOR][0], ColorChoose[LINE_COLOR][1], ColorChoose[LINE_COLOR][2]);
glBegin(GL_LINE_STRIP);
for (count = 0; count <= sections; count++)
{
glVertex2f(x + radius*cos(count*TWOPI / sections), y + radius*sin(count*TWOPI / sections));
}
glEnd();
}
//嘴巴
void mouthhalf(float x, float y, float radius)
{
int count;
int sections = 200;
GLfloat TWOPI = 2.0f * 3.14159f;
//glLineWidth(1.f);
glColor3f(ColorChoose[NOSE_COLOR][0], ColorChoose[NOSE_COLOR][1], ColorChoose[NOSE_COLOR][2]);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
for (count = 100; count <=