2021年5月31日 星期一

是你是你反詐騙 Week15

 

🛸Week15 存檔 讀檔🛸

✨存檔

🔼用fopen() fprintf()寫檔案

🧷程式

#include <stdio.h>///外掛
int main(int argc,char ** argv)
{
    FILE*fout=NULL;///file output 變數
    fout=fopen("檔名.txt","w+");///開啟檔案 檔名.txt,模式:write

    printf(     "Hello World\n");///小黑視窗的文字
    fprintf(fout,"Hello World\n");///檔名.txt中的文字
}
____________________________________________________
✨修改專案目錄

🔼打開.cbp

🔼修改程式碼後

🔼修改專案目錄後

__________________________________________

✨讀檔

🧷程式

#include <stdio.h>
int main(int argc,char ** argv)
{
    FILE*fin=NULL;///讀檔
    fin=fopen("file.txt","r");///開啟檔案(Read

    char line[100];
    fscanf(fin,"%s",line);
    printf("Read %s \n",line);

    fscanf(fin,"%s",line);
    printf("Read %s \n",line);
}
__________________________________________

✨先畫茶壺 專案檔放入freeglut.dll


























🧷程式

#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<90)diff=+2;
    glutPostRedisplay();///有空時重新Redisplay
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glutSolidTeapot(0.3);///身體
        glutSolidTeapot(0.3);///左手臂
        glutSolidTeapot(0.3);///左手肘
        glutSolidTeapot(0.3);///右手臂
        glutSolidTeapot(0.3);///右手肘
    glutSwapBuffers();
}
int main(int argc,char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week15ManyAngles");

    glutDisplayFunc(display);
    glutMainLoop();
}
----------------------------------------------------------
✨手臂轉動

🧷程式

#include <stdio.h>
#include <GL/glut.h>
float angle=0, diff=2;///上週程式,會增加、會減少!!!
///float angle[20]={};//都是0的陣列 angle
void timer(int t)///上週程式,會增加、會減少!!!
{
    glutTimerFunc( 30, timer, t+1 );///上週程式 設定新的timer
    angle += diff;///上週程式,會增加、會減少!!!
    if(angle>90) diff = -2;///上週程式,會增加、會減少!!!
    if(angle<0) diff = +2;///上週程式,會增加、會減少!!!
    glutPostRedisplay();///上週教display();
}
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();///Step05-2
        glutSolidTeapot( 0.3 );///身體
        glPushMatrix();///Step05-2
            glTranslatef(-0.3,0,0);
            glRotatef(angle, 0,0,1);
            glTranslatef(-0.3,0,0);
            glutSolidTeapot( 0.3 );///左手臂, 但是,要用 T-R-T移位置
            glPushMatrix();
                glTranslatef(-0.3, 0,0);
                glRotatef(angle, 0,0,1);
                glTranslatef(-0.3, 0,0);
                glutSolidTeapot( 0.3 );///左手肘
            glPopMatrix();
        glPopMatrix();///Step05-2
        glPushMatrix();///Step05-2
            glutSolidTeapot( 0.3 );///右手臂
            glutSolidTeapot( 0.3 );///右手肘
        glPopMatrix();///Step05-2
    glPopMatrix();///Step05-2
    glutSwapBuffers();
}
int main( int argc, char** argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow( "week15 many angles" );

    glutDisplayFunc( display );
    glutTimerFunc( 0, timer, 0);
    glutMainLoop();
}///先不放貼圖, 先不放打光

--------------------------------------------------
✨兩手臂轉動

🧷程式

#include <stdio.h>
#include <GL/glut.h>
float angle=0, diff=2;///上週程式,會增加、會減少!!!
///float angle[20]={};//都是0的陣列 angle
void timer(int t)///上週程式,會增加、會減少!!!
{
    glutTimerFunc( 30, timer, t+1 );///上週程式 設定新的timer
    angle += diff;///上週程式,會增加、會減少!!!
    if(angle>90) diff = -2;///上週程式,會增加、會減少!!!
    if(angle<0) diff = +2;///上週程式,會增加、會減少!!!
    glutPostRedisplay();///上週教display();
}
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();///Step05-2
        glutSolidTeapot( 0.3 );///身體
        glPushMatrix();///Step05-2
            glTranslatef(-0.3,0,0);
            glRotatef(angle, 0,0,1);
            glTranslatef(-0.3,0,0);
            glutSolidTeapot( 0.3 );///左手臂, 但是,要用 T-R-T移位置
            glPushMatrix();
                glTranslatef(-0.3, 0,0);
                glRotatef(angle, 0,0,1);
                glTranslatef(-0.3, 0,0);
                glutSolidTeapot( 0.3 );///左手肘
            glPopMatrix();
        glPopMatrix();///Step05-2
        glPushMatrix();///Step05-2
            glTranslatef(+0.3,0,0);
            glRotatef(-angle, 0,0,1);
            glTranslatef(+0.3,0,0);
            glutSolidTeapot( 0.3 );///右手臂
            glPushMatrix();///step05-3
                glTranslatef(+0.3,0,0);
                glRotatef(-angle, 0,0,1);
                glTranslatef(+0.3,0,0);
                glutSolidTeapot( 0.3 );///右手肘
            glPopMatrix();///Step05-3
        glPopMatrix();///Step05-2
    glPopMatrix();///Step05-2
    glutSwapBuffers();
}
int main( int argc, char** argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow( "week15 many angles" );

    glutDisplayFunc( display );
    glutTimerFunc( 0, timer, 0);
    glutMainLoop();
}///先不放貼圖, 先不放打光





沒有留言:

張貼留言

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

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