2023年5月3日 星期三

chiche_week12

Week12

step01

程式碼:

#include <stdio.h>
int main()
{
FILE * fout = fopen("file.txt","w");
printf("Hello World\n");
fprintf(fout,"Hello World在檔案裡\n");
}


step02

到檔案總管中,有新的file.txt檔案

step03

程式碼:

#include <stdio.h>
int main()
{
FILE * fin = fopen("file.txt", "r");
char line[100];
fscanf(fin, "%s" , line);
printf("從file.txt讀到了: %s\n",line);
fscanf(fin , "%s" , line);
printf("從file.txt讀到了: %s\n",line);
}

step04

執行 :


(讀取到空格 所以字分開)


程式碼:

#include <stdio.h>
int main()
{
int a[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
int b[10] = {};
FILE * fout = fopen("file3.txt","w");
for(int i=0 ; i<10 ; i++)
{
printf("%d ",a[i]);
fprintf(fout,"%d ",a[i]);
}
printf("\n");
fprintf(fout,"\n");
fclose(fout);
FILE * fin = fopen("file3.txt","r");
for(int i=0 ; i<10 ; i++)
{
fscanf(fin,"%d", &b[i]);
printf("b%d:%d ",i, b[i]);
}
fclose(fin);
}

step05

執行: 



step06

程式碼:

#include <stdio.h>
#include <GL/glut.h>
float teapotX=0 , teapotY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
teapotX = (x-150)/150.0;
teapotY = (150-y)/150.0;
}
display();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}


(用滑鼠點會移動位置)

step07


(座標點會存在檔案總管中(freeglut/bin)資料夾裡面)

執行 : 

(按滑鼠的畫面)

(按空白鍵畫面會重複一次)

程式碼:

#include <stdio.h>
#include <GL/glut.h>
FILE * fout = NULL;
FILE * fin = NULL;
float teapotX=0 , teapotY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
teapotX = (x-150)/150.0;
teapotY = (150-y)/150.0;
if(fout==NULL) fout = fopen("file4.txt","w");
fprintf(fout, "%f %f\n",teapotX , teapotY);
}
display();
}
void keyboard(unsigned char key,int x,int y)
{
if (fin==NULL)
{
fclose(fout);
fin = fopen("file4.txt","r");
}
fscanf(fin,"%f %f",&teapotX , &teapotY);
display();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}

step08


工作目錄不合理,要修改


step09


freeglut.dill複製到專案裡
需要修改 (Release)

step10

上傳檔案git指令

1. git指令
2. cd desktop
3. git clone https://github.com/你的帳號/2023graphicsa
4. cd 2023graphicsa
5. start .
6. git add . 
7. git status

8. git config --global user.email "電子郵件"

9. git config --global user.name "帳號名chiche0306"

10. git commit -m "week"

11. git push


沒有留言:

張貼留言