#includestdio.h
int main(int argc,char argv)
{
FILE fout=NULL;
fout=fopen(檔名.txt,w+);
printf(Hello World1n);
fprintf(fout,Hello World1n);
FILEfin=NULL;
fin=fopen(檔名.txt,r);
char line[100];
fscanf(fin,%s,line);
printf(Now read is %s n,line);
fscanf(fin,%s,line);
printf(Now read is %s n,line);
}
存檔與讀檔
茶壺當手臂旋轉
#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();
}///先不放貼圖, 先不放打光
沒有留言:
張貼留言