2021年5月31日 星期一

現在開始斗內Week15

 電腦圖學

1.存檔

#include <stdio.h>
int main(int argc, char **argv)
{
   FILE*fout=NULL;
   fout=fopen("hi.txt","w+");
   printf("hollow\n");
   fprintf(fout,"hollow");
}

2.讀檔

#include <stdio.h>
int main(int argc, char **argv)
{
   //FILE*fout=NULL;
   //fout=fopen("hi.txt","w+");
   //printf("hollow\n");
   //fprintf(fout,"hollow");
   FILE*fin=NULL;
   fin=fopen("hi.txt","r");
   char line[100];
   fscanf(fin,"%s",line);
   printf("%s\n",line);
}

3.四關節

#include <GL/glut.h>
int angle=0;
int diff=2;
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);///設下個timer
    angle+=diff;
    if(angle>90||angle<0)diff=-diff;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(-0.3,0,0);
            glRotatef(angle,0,0,1);
            glTranslatef(-0.3,0,0);
            glutSolidTeapot(0.3);
            glPushMatrix();
                glTranslatef(-0.3,0,0);
                glRotatef(angle,0,0,1);
                glTranslatef(-0.3,0,0);
                glutSolidTeapot(0.3);
            glPopMatrix();
        glPopMatrix();
        glPushMatrix();
            glTranslatef(0.3,0,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.3,0,0);
            glutSolidTeapot(0.3);
            glPushMatrix();
                glTranslatef(0.3,0,0);
                glRotatef(angle,0,0,1);
                glTranslatef(0.3,0,0);
                glutSolidTeapot(0.3);
            glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);///初始化
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);///顯示模式
    glutCreateWindow("HI");///開視窗
    glutDisplayFunc(display);///顯示函式
    glutTimerFunc(0,timer,0);
    glutMainLoop();///主迴圈,卡住他
}










沒有留言:

張貼留言

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

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