1.作業互評
找出三個認為較佳的作品

2.用程式畫一個正圓
以下為程式碼:
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <stdio.h>
void display()
{
glBegin(GL_POLYGON);
for(float angle=0;angle<=3.1415926*2;angle+=0.01){
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
{
glBegin(GL_POLYGON);
for(float angle=0;angle<=3.1415926*2;angle+=0.01){
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160401");
glutDisplayFunc(display);
//glutMouseFunc(mouse);
// glutMotionFunc(motion);
glutMainLoop();
}
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160401");
glutDisplayFunc(display);
//glutMouseFunc(mouse);
// glutMotionFunc(motion);
glutMainLoop();
}
3.點圓形可變顏色
以下為程式碼:
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <stdio.h>
void display()
{
glBegin(GL_POLYGON);
for(float angle=0;angle<=3.1415926*2;angle+=0.01){
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
{
glBegin(GL_POLYGON);
for(float angle=0;angle<=3.1415926*2;angle+=0.01){
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button,state,x,y);
glColor3f(1, x/300.0, y/300.0);
}
{
printf("%d %d %d %d\n",button,state,x,y);
glColor3f(1, x/300.0, y/300.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160401");
glutDisplayFunc(display);
glutMouseFunc(mouse);
// glutMotionFunc(motion);
glutMainLoop();
}
4.點一下滑鼠就可一直變換色彩

以下為程式碼:
#include <GL/glut.h>#include <math.h>
#include <stdio.h>
void display()
{
glBegin(GL_POLYGON);
for(float angle=0;angle<=3.1415926*2;angle+=0.01){
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
}
void motion(int x,int y)
{
glColor3f(1, x/300.0, y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160401");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
5.畫小精靈

以下為程式碼:
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0, 0);
for(float angle=0 + mouth; angle <= 3.1415926 *2 - mouth; angle +=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion (int x,int y)
{
mouth=x/300.0;
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
return EXIT_SUCCESS;
}

以下為程式碼:
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0, 0);
for(float angle=0 + mouth; angle <= 3.1415926 *2 - mouth; angle +=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion (int x,int y)
{
mouth=x/300.0;
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
return EXIT_SUCCESS;
}
沒有留言:
張貼留言