2017年6月30日 星期五

Week 04 語璇電圖

一、使用滑鼠點擊得到座標畫圖
1.程式

















加入stdio.h , math.h
然後加入
void mouse(int button,int state,int x, int y)
{
    printf("%d %d %d %d\n", button, state, x, y);
}
int main(int argc, char *argv[])
{
    glutMouseFunc(mouse);
}
印出滑鼠點擊的狀態和座標
button : 0=左鍵 2=右鍵 1=中鍵
state : 0=按下 1=放開

2.結果
按下:












放開:










二、用滑鼠點擊改變顏色











加入

void mouse(int button,int state,int x, int y)
{
    glColor3f(1,x/300.0,y/300.0);
    glutPostRedisplay();
}

點擊左上角變成紅色

三、使用滑鼠拖曳連續改變顏色
程式













加入
void motion(int x, int y)
{
    printf("%d %d\n", x, y);
    glColor3f(1,x/300.0,y/300.0);
    glutPostRedisplay();
}
int main(int argc, char *argv[])
{
    glutMotionFunc(motion);
}

點擊左鍵移動改變顏色


四、使用滑鼠作標做出小精靈
1.程式



沒有留言:

張貼留言