/* snow3.c - Don Yang (uguu.org) 11/28/03 */ #include #include #include #include #include #include #include #include #define q() ((rand() & 4095) / 4095.) typedef double e; struct { e x, y, z, u, v, w, i, j, k, p, q, r, a, b, c, d; int o; } _[128], *f; struct timeb t; e p, d, b, r[8], a[8]; int i, j, k, s = 256; void C() { f->x = f->i = q() * s * 4 - s * 2; f->y = f->j = s; f->z = f->k = q() * s * 4 - s * 2; f->p = q() * s * 4 - s * 2; f->q = -s - q() * s * 4; f->r = q() * s * 4 - s * 2; f->u = q() * s; f->a = q() * 10; f->v = q() * s; f->b = q() * 10; f->w = q() * s; f->c = q() * 10; f->d = d; r[0] = 8; a[0] = 0; for(j = 1; j < 7; j++) { r[j] = q() * 5 + 3; a[j] = q() * p / 2; } r[j] = 3; a[j] = p / 2; glNewList(f->o, GL_COMPILE); glBegin(GL_LINE_LOOP); for(k = j = 0; k < 6; k++) { for(; j < 7; j++) glVertex3d(r[j] * cos(k * p + a[j]), r[j] * sin(k * p + a[j]), 0); for(; j > 0; j--) glVertex3d(r[j] * cos((k + 1) * p - a[j]), r[j] * sin((k + 1) * p - a[j]), 0); } glEnd(); glEndList(); } void D() { glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, i = glutGet(GLUT_WINDOW_WIDTH), j = glutGet(GLUT_WINDOW_HEIGHT)); if( i > j ) { b = i / (e)j; d = 1; } else { b = 1; d = j / (e)i; } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-b, b, -d, d, 10, 2000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, -1000, 0, 0, 0, 0, 1, 0); glColor4f(.8, .9, 1, .5); f = _; for(i = 0; i < s / 2; i++) { glPushMatrix(); glTranslated(f->x, f->y, f->z); glRotated(f->u, 1, 0, 0); glRotated(f->v, 0, 1, 0); glRotated(f->w, 0, 0, 1); glCallList((f++)->o); glPopMatrix(); } glutSwapBuffers(); glFlush(); } void R(int w, int h) { glutPostRedisplay(); } void A() { ftime(&t); d = t.time + t.millitm / 1000.; f = _; for(i = 0; i < s / 2; i++, f++) { f->y = f->j + (f->q - f->j) * (b = (d - f->d) / 16); if( f->y < -s ) { C(); } else { f->x = f->i + (f->p - f->i) * b; f->z = f->k + (f->r - f->k) * b; f->u += f->a; f->v += f->b; f->w += f->c; } } R(0, 0); } void Q(unsigned char c, int u, int v) { glFlush(); for(i = 0; i < s / 2; glDeleteLists(_[i++].o, 1)); exit(0); } int main(int u, char **v) { srand(time(0)); p = atan2(0, -1) / 3; glutInit(&u, v); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("winter wish"); glutDisplayFunc(D); glutIdleFunc(A); glutReshapeFunc(R); glutKeyboardFunc(Q); ftime(&t); d = t.time + t.millitm / 1000.; f = _; for(i = 0; i < s / 2; i++) { f->o = glGenLists(1); C(); (f++)->q -= s * 2; } glEnable(GL_BLEND); glClearColor(0, 0, 0, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glutMainLoop(); return 0; }