2021年3月22日 星期一

Bunny-week05


 (1)Transformation

#include <GL/glut.h>
#include <stdio.h>
float vx[2000], vy[2000];///準備一堆頂點,等一下要畫,介於-1~+1
int N=0;///有N個頂點
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glBegin(GL_LINE_LOOP);
    for(int i=0;i<N;i++){
        glVertex2f(vx[i],vy[i]);
    }
    glEnd();
    glutSwapBuffers();///交換兩倍的buffers
}
void mouse(int buttin,int state,int x,int y)
{

}

void motion(int x,int y)
{
    printf("%d %d\n",x,y);///把頂點記下來...等一下要畫
    vx[N]=(x-150)/150.0;///很像這樣的寫法,記錄下來...
    vy[N]=-(y-150)/150.0;
    display();
}           ///減一下,在除一半,y加負號
int main(int argc,char ** argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160846");


    glutDisplayFunc(display);///第二週
    glutMouseFunc(mouse);///第四週 按下去、彈起來
    glutMotionFunc(motion);///第四週mouse motion在動(拖曳)/在畫
    glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float vx[2000], vy[2000];///準備一堆頂點,等一下要畫,介於-1~+1
int N=0;///有N個頂點
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glColor3f(1,1,0);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0,0);
    for(int i=0;i<N;i++){
        glVertex2f(vx[i],vy[i]);
    }
    glEnd();
    glutSwapBuffers();///交換兩倍的buffers
}
void mouse(int buttin,int state,int x,int y)
{

}

void motion(int x,int y)
{
    printf("%d %d\n",x,y);///把頂點記下來...等一下要畫
    vx[N]=(x-150)/150.0;///很像這樣的寫法,記錄下來...
    vy[N]=-(y-150)/150.0;
    N++;
    display();
}           ///減一下,在除一半,y加負號
int main(int argc,char ** argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 drawing");


    glutDisplayFunc(display);///第二週
    glutMouseFunc(mouse);///第四週 按下去、彈起來
    glutMotionFunc(motion);///第四週mouse motion在動(拖曳)/在畫
    glutMainLoop();
}










沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...