2017年3月13日 星期一

2017 Week03 ID張凱盛

1.今天從上次的茶壺繼續

加入 mouse 函式 確認滑鼠位置和參數


void mouse(int button, int state, int x, int y)
{
    printf("%d %d %d %d\n", button, state, x, y);
}



加上變色的程式碼

void mouse(int button, int state, int x, int y)
{
    printf("%d %d %d %d\n", button, state, x, y);
    glColor3f( 50 , x/300.0, y/300.0);
    glutPostRedisplay();
}




加上 motiont 程式

void motion(int x, int y)
{
    printf("%d %d\n", x, y);
    glColor3f( 50 , x/300.0, y/300.0);
    glutPostRedisplay();
}



2.更改程式畫出一個圓

#include <Gl/glut.h>
#include <stdio.h>
#include <math.h>

void mouse(int button, int state, int x, int y)
{
    printf("%d %d %d %d\n", button, state, x, y);

}

void motion(int x, int y)
{
    printf("%d %d\n", x, y);
    glColor3f( 50 , x/300.0, y/300.0);
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_POLYGON);
    for(float angle= 0;angle<3.14159*2;angle+=0.0001)
    {
        glVertex2f( cos(angle),sin(angle));
    }
    glEnd();
    glutSwapBuffers();
}

int main(int argc, char*argv[])
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow(" 04160312 ");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();

}








沒有留言:

張貼留言