2021年6月3日 星期四

week 15

 

Week15

1.     讀檔案(會在下方找到文件路徑)

#include <stdio.h>///step01:外挂

int main(int argc,char ** argv)

{

    FILE*fout=NULL;///step01:檔案指標file output變數

    fout=fopen("week14.txt","w+");///開啓檔案,檔名week14.txt,模式write

    printf("hello world\n");

    fprintf(fout,"hello world\n");///改裝

}

2.     改存檔路徑

專案中程式碼的Working_dir改成 .

3.     讀檔

#include <stdio.h>///step01:外挂

int main(int argc,char ** argv)

{

    FILE * fin=NULL;///step03:改成讀檔

    fin=fopen("week14.txt","r");///read模式

    char line[100];

    fscanf(fin,"%s",line);///讀入字串

    printf("現在讀到的是 %s \n",line);

 

    fscanf(fin,"%s",line);///再讀入字串

    printf("現在讀到的是 %s \n",line);

}

4.     貼茶壺

#include <stdio.h>

#include <GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glutSolidTeapot(0.3);

    glutSwapBuffers();

}

int main(int argc,char ** argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week15");

 

    glutDisplayFunc(display);

    glutMainLoop();

}

5.     多個茶壺的轉動


#include <stdio.h>

#include <GL/glut.h>

float angle=0,diff=2;

void timer(int t)

{

    glutTimerFunc(30,timer,t+1);

    angle+=diff;

    if(angle>90) diff=-2;

    if(angle<0) diff=+2;

    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_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week15");

 

    glutDisplayFunc(display);

    glutTimerFunc(0,timer,0);

    glutMainLoop();

}




沒有留言:

張貼留言

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

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