2016年3月14日 星期一

出木杉英才的學霸之路 Week04

回家作業1:
選出5張上周作業做得比較好的圖上傳moodle
1.劉子豪
2.李耀明

3.鄭棕寶

4.陳奕中

5.黃慧緣


課堂作業2:平移、旋轉、縮放
照著上周的課堂作業1,打開Transformati,調整圖片的平移、旋轉、縮放

課堂作業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(148/255.0,201/255.0,255/255.0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(255,242,42);
    glBegin(GL_POLYGON);
    glVertex2f((77-150)/150.0, -(135-150)/150.0);
    glVertex2f((79-150)/150.0, -(128-150)/150.0);
    glVertex2f((83-150)/150.0, -(117-150)/150.0);
    glVertex2f((94-150)/150.0, -(109-150)/150.0);
    glVertex2f((99-150)/150.0, -(105-150)/150.0);
    glVertex2f((107-150)/150.0, -(104-150)/150.0);
    glVertex2f((125-150)/150.0, -(103-150)/150.0);
    glVertex2f((126-150)/150.0, -(103-150)/150.0);
    glVertex2f((131-150)/150.0, -(109-150)/150.0);
    glVertex2f((137-150)/150.0, -(113-150)/150.0);
    glVertex2f((142-150)/150.0, -(123-150)/150.0);
    glVertex2f((142-150)/150.0, -(134-150)/150.0);
    glVertex2f((143-150)/150.0, -(151-150)/150.0);
    glVertex2f((140-150)/150.0, -(163-150)/150.0);
    glVertex2f((135-150)/150.0, -(172-150)/150.0);
    glVertex2f((135-150)/150.0, -(172-150)/150.0);
    glVertex2f((122-150)/150.0, -(175-150)/150.0);
    glVertex2f((116-150)/150.0, -(173-150)/150.0);
    glVertex2f((111-150)/150.0, -(171-150)/150.0);
    glVertex2f((103-150)/150.0, -(166-150)/150.0);
    glVertex2f((97-150)/150.0, -(159-150)/150.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello3D");
    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(148/255.0,201/255.0,255/255.0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(255,242,42);
    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();
    glPushMatrix();
    glTranslatef(0,0.4,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();
    glPushMatrix();
    glTranslatef(0.4,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();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}




1 則留言: