http://jsyeh.org/processing/spirograph/
萬花尺 很好玩! 用遞增角度去畫星星
https://github.com/jsyeh/processing/commits?author=jsyeh
老師的github! 以後直接點比較方便
跟鍵盤連線按下w a d建會快速旋轉
程式碼
#include <GL/glut.h>
int N=0,vx[3000],vy[3000];
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glBegin(GL_LINE_LOOP);
for(int i=0;i<N;i++){
glVertex2f((vx[i]-150)/150.0,-(vy[i]-150)/150.0);
}
glEnd();
glPushMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x, int y)
{
angle++;
display();
}
void motion(int x, int y)
{
vx[N]=x;vy[N]=y;
N++;
display();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("你的歡迎!");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMotionFunc(motion);
glutMainLoop();
}


沒有留言:
張貼留言