2017年3月14日 星期二

Week04 三個ㄌ 的 課堂筆記

1.作業互評

老師希望我們以上周作業,讓我們從同學中挑出認為自己最好的3個作品(◕‿◕✿)

(我覺得大嘴鳥很可愛也很像(✪‿✪)ノ)

(我要推薦我自己,我的花媽超可愛也是我的心血(๑◕ㅂ▰))

(這垃圾鴿超用心我很喜歡(●´艸`))

2.畫出正圓形

因為我們上禮拜都無法畫出正圓形,老師教我們使用程式畫正圓形(♡´艸`)


#include <GL/glut.h>
#include <math.h>
void display()
{

    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("04160594 Number 1");
    glutDisplayFunc(display);
    glutMainLoop();
}

已上是畫圓所使用到的程式碼( ´∀`)


3.進階-點擊滑鼠變顏色

一直點擊滑鼠可以變顏色喔ψ(`∇´)ψ


#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)
{
    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("GLUT Shapes");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();

    return EXIT_SUCCESS;

}
已上是變顏色所使用到的程式碼{*≧∀≦}


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)
{
   // printf("%d %d %d %d\n",button,state,x,y);
   // glColor3f(1,x/300.0,y/300.0);
}
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("GLUT Shapes");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotiFunc(motion);
    glutMainLoop();

    return EXIT_SUCCESS;

}
已上是變顏色所使用到的程式碼o(^▽^)o

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 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);
}
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);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();

    return EXIT_SUCCESS;
}
已上是畫小精靈所使用到的程式碼(๑•́ω•̀)

沒有留言:

張貼留言