目標:用程式碼開啟記事本檔案 並寫入文字
#include <stdio.h>
int main()
{
int a[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
FILE * fout = fopen("motion.txt","w+");
//fprintf(fout, "hello world\n");
for(int i=0;i<16;i++)
{
fprintf(fout,"%d ",a[i]);
}
fprintf(fout,"\n");
for(int i=0;i<16;i++)
{
fprintf(fout,"%d ",a[i]);
}
}
彩色水壺
#include <GL/glut.h>
int angle[10]={0,0,0,0,0, 0,0,0,0,0};
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1,1,1);///白色
glutSolidTeapot(0.3);///body
glPushMatrix();///右邊
glTranslatef(0.3, 0,0);
glRotatef(angle[0], 0,0,1);///轉動
glTranslatef(0.2, 0,0);///最重要,旋轉中心要放在中心
glColor3f(1,0,0);///紅色
glutSolidTeapot(0.2);///右上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0);
glRotatef(angle[1], 0,0,1);
glTranslatef(0.2, 0,0);
glColor3f(1,1,0);///黃
glutSolidTeapot(0.2);
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊
glTranslatef(-0.3, 0,0);
glRotatef(angle[3], 0,0,1);///轉動
glTranslatef(-0.2, 0,0);///最重要,旋轉中心要放在中心
glColor3f(0,1,0);///綠色
glutSolidTeapot(0.2);///左上手臂
glPushMatrix();
glTranslatef(-0.2, 0,0);
glRotatef(angle[4], 0,0,1);
glTranslatef(-0.2, 0,0);
glColor3f(0,0,1);///藍色
glutSolidTeapot(0.2);///左下手臂
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week14 file");
glutDisplayFunc(display);
glutMainLoop();
}


沒有留言:
張貼留言