2021年5月25日 星期二

周球隊長

圓形的程式碼 

#include <GL/glut.h>

void display(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidSphere(0.3,30,30);///畫一個實心圓(半徑,縱切,橫片切)
   /*glutSolidSphere(0.3,30,30); ///Solid實體(1-1)
     glutWireSphere(0.3,30,30); ///Wire線(1-3)
   */
    glutSwapBuffers();
}
void timer(int t){
    glClearColor(1,1,0,0);///背景變黃色(1-2),(1-3)
    display();
}
int main(int argc, char** argv){
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week14");
    glutDisplayFunc(display);
    glutTimerFunc(4000,timer,0);///時間,使用的函式,參數
    glutMainLoop();
}
讓方形轉動的程式碼

#include <GL/glut.h>

int angle=0;

void display(){

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidCube(0.3);///一個正方形

#include <GL/glut.h>

int angle=0;

void display(){

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidCube(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

int diff=1;///加一個判斷用的整數

void timer(int t){

    glutTimerFunc(20,timer,t+1);///(速度,使用的函式,參數)

    angle+=diff;///(角度旋轉)

    if(angle>180)diff=-diff;///超過180度,開始反轉

    if(angle<0)diff=-diff;

    display();

}

int main(int argc,char** argv){

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("week14 timer");

    glutDisplayFunc(display);

    glutTimerFunc(1000,timer,0);///(定時,函式,參數)

    glutMainLoop();

}

沒有留言:

張貼留言

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

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