2016年3月14日 星期一

20160314情人節

課堂作業1:



課堂作業2:



課堂作業3:


#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x, int y)
{
    if(state==GLUT_DOWN)
    printf("    glVertex2f( (%d-150)/150.0, -(%d-150)/150.0); \n",x,y);
}
void display()
{
    glClearColor(150/255.0,170/255.0,55/255.0,1);//綠色
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(157,136,244);//紫色
    glBegin(GL_POLYGON);
    glVertex2f( (16-150)/150.0, -(21-150)/150.0);
    glVertex2f( (17-150)/150.0, -(76-150)/150.0);
    glVertex2f( (105-150)/150.0, -(14-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);
    glVertex2f( (202-150)/150.0, -(15-150)/150.0);
    glVertex2f( (278-150)/150.0, -(72-150)/150.0);
    glVertex2f( (286-150)/150.0, -(16-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);
    glVertex2f( (14-150)/150.0, -(180-150)/150.0);
    glVertex2f( (19-150)/150.0, -(255-150)/150.0);
    glVertex2f( (93-150)/150.0, -(247-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);
    glVertex2f( (213-150)/150.0, -(255-150)/150.0);
    glVertex2f( (275-150)/150.0, -(256-150)/150.0);
    glVertex2f( (274-150)/150.0, -(191-150)/150.0);
    glEnd();
    glBegin(GL_POLYGON);
    glVertex2f( (143-150)/150.0, -(64-150)/150.0);
    glVertex2f( (83-150)/150.0, -(132-150)/150.0);
    glVertex2f( (160-150)/150.0, -(193-150)/150.0);
    glVertex2f( (236-150)/150.0, -(141-150)/150.0);
    glEnd();
    glutSwapBuffers();
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);//滑鼠
    glutMainLoop();
}

課堂作業4:


圓形:



#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button,int state,int x, int y)
{
    if(state==GLUT_DOWN)
    printf("    glVertex2f( (%d-150)/150.0, -(%d-150)/150.0); \n",x,y);
}
void display()
{
    glClearColor(150/255.0,170/255.0,55/255.0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(157,136,244);

    glPushMatrix();
         glBegin(GL_POLYGON);
         for(float angle=0;angle<3.14159265357989 *2;angle+=0.1){
             glVertex2f(0.2 *cos(angle), 0.2*sin(angle));
         }
         glEnd();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(0, 0.5 ,0);
        glBegin(GL_POLYGON);
        for(float angle=0;angle<3.14159265357989*2;angle+=0.1)
         {
             glVertex2f(0.2 *cos(angle), 0.2*sin(angle));
         }
         glEnd();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(-0.5, 0 ,0);
        glBegin(GL_POLYGON);
        for(float angle=0;angle<3.14159265357989 *2;angle+=0.1)
         {
             glVertex2f(0.2 *cos(angle), 0.2*sin(angle));
         }
         glEnd();
    glPopMatrix();

    glutSwapBuffers();
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


沒有留言:

張貼留言