2021年3月22日 星期一

如果仰臥起坐有8 week05

1.自轉與公轉的差別

    (點選右鍵 swap)

2.怎麼看程式碼

    (由下往上去理解)

3.用mouse畫圖

#include <GL/glut.h>
#include <stdio.h>
float vx[2000], vy[2000];
int N=0;
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();
}
void mouse(int botton,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();
}

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

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

4.畫出來的圖有顏色

#include <GL/glut.h>
#include <stdio.h>
float vx[2000], vy[2000];
int N=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    ///glBegin(GL_LINE_LOOP);
    glColor3f(1,1,1);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0,0);
    for(int i=0; i<N; i++){
        glVertex2f(vx[i], vy[i]);
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int botton,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();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160431如 week05");
    glutDisplayFunc(display);
    glutMouseFunc( mouse );
    glutMotionFunc(motion);
    glutMainLoop();
}

5.github

沒有留言:

張貼留言

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

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