本周第三次線上上課!感覺已經抓到線上上課的訣竅了!!!!!!
程式碼:
#include <stdio.h>
int main(int argc,char** argv)
{
FILE*fout=NULL;
fout=fopen("檔名.txt","w+");
printf("Hello World\n");
fprintf(fout,"Hello World\n");
}
利用以上程式碼可將hello world存取至記事本當中,並印出hello world
將working_dir改成"."
執行結果如上
#include <stdio.h>
int main(int argc,char** argv)
{
FILE*fin=NULL;
fin=fopen("檔名.txt","r");
char line[100];
fscanf(fin,"%s",line);
printf("現在讀到的是%s\n",line);
fscanf(fin,"%s",line);
printf("現在讀到的是%s\n",line);
}
程式碼:
#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 many angles");
glutDisplayFunc(display);
glutMainLoop();
}
繪製一個新茶壺
茶壺轉動程式碼:
#include <stdio.h>
#include<GL/glut.h>
float angle=0;
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);
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("week15 many angles");
glutDisplayFunc(display);
glutTimerFunc();
glutMainLoop();
}
#include <stdio.h>
#include<GL/glut.h>
float angle=0;
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();
glutTranslatef(-0.3,0,0);
glRotatef(angle,0,0,1);
glutTranslatef(-0.3,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glutTranslatef(+0.3,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15 many angles");
glutDisplayFunc(display);
glutTimerFunc();
glutMainLoop();
}
程式碼:(手臂轉動)
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
float diff=2;
///float angle=[20];
void timer (int t)
{
glutTimerFunc(30,timer,t+1); ///設定新的timer(等多久,timer ,參數)
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 ); ///左手臂, 但是,要用 T-R-T移位置
glPushMatrix();
glTranslatef(-0.3, 0,0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.3, 0,0);
glutSolidTeapot( 0.3 ); ///左手肘
glPopMatrix();
glPopMatrix();
glPushMatrix();
glutSolidTeapot( 0.3 ); ///右手臂
glutSolidTeapot( 0.3 ); ///右手肘
glPopMatrix();
glPopMatrix();
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;
float diff=2;
///float angle=[20];
void timer (int t)
{
glutTimerFunc(30,timer,t+1); ///設定新的timer(等多久,timer ,參數)
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 );///左手臂, 但是,要用 T-R-T移位置
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 many angles");
glutDisplayFunc(display);
glutTimerFunc(0,timer,0);
glutMainLoop();
}
程式碼:(一邊手臂動起)
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
float diff=2;
///float angle=[20];
void timer (int t)
{
glutTimerFunc(30,timer,t+1); ///設定新的timer(等多久,timer ,參數)
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 );///左手臂, 但是,要用 T-R-T移位置
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 many angles");
glutDisplayFunc(display);
glutTimerFunc(0,timer,0);
glutMainLoop();
}

程式碼:(雙手手臂動起)
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
float diff=2;
///float angle=[20];
void timer (int t)
{
glutTimerFunc(30,timer,t+1); ///設定新的timer(等多久,timer ,參數)
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 ); ///左手臂, 但是,要用 T-R-T移位置
glPushMatrix();
glTranslatef(-0.3, 0,0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.3, 0,0);
glutSolidTeapot( 0.3 ); ///左手肘
glPopMatrix();
glPopMatrix();
glPushMatrix();
glutSolidTeapot( 0.3 ); ///右手臂
glutSolidTeapot( 0.3 ); ///右手肘
glPopMatrix();
glPopMatrix();
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();
}
沒有留言:
張貼留言