Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <time.h>
- #include <vector>
- #include <gl/glut.h>
- #define intensivity 1
- using namespace std;
- GLfloat WinW = 800, WinH = 600;
- int gen[] = { -1, 0, 1 };
- class SnowFlake {
- public:
- GLfloat x;
- GLfloat y;
- GLfloat direction;
- bool fell;
- SnowFlake();
- };
- SnowFlake::SnowFlake() {
- x = rand() % int(WinW);
- y = WinH;
- direction = gen[rand() % 3];
- fell = false;
- }
- vector<SnowFlake> SnowFlakes;
- void draw() {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- glPushMatrix();
- glColor3f(1, 1, 1);
- glBegin(GL_POINTS);
- for (unsigned int i = 0; i < SnowFlakes.size(); i++) {
- glVertex2f(SnowFlakes[i].x, SnowFlakes[i].y);
- }
- glEnd();
- glPopMatrix();
- glutSwapBuffers();
- }
- void Timer(int value) {
- int n = 0;
- for (unsigned int i = 0; i < SnowFlakes.size(); i++) {
- if (SnowFlakes[i].y > n) {
- SnowFlakes[i].y--;
- SnowFlakes[i].x += SnowFlakes[i].direction;
- SnowFlakes[i].direction = gen[rand() % 3];
- }
- if (SnowFlakes[i].y <= n) {
- SnowFlakes[i].direction = gen[rand() % 3];
- SnowFlakes[i].x += SnowFlakes[i].direction;
- n++;
- }
- }
- for (int i = 0; i < intensivity; i++) SnowFlakes.push_back(SnowFlake());
- glutPostRedisplay();
- glutTimerFunc(3, Timer, 1);
- }
- void reshape(GLsizei WW, GLsizei WH) {
- glViewport(0, 0, WW, WH);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, WinW, 0, WinH, 0, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- int main(int argc, char** argv) {
- srand(time(NULL));
- for (int i = 0; i < intensivity; i++) {
- SnowFlakes.push_back(SnowFlake());
- }
- glutInit(&argc, argv);
- glutInitWindowSize(WinW, WinH);
- glutInitWindowPosition(100, 100);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- glutCreateWindow("RGR 12");
- glutDisplayFunc(draw);
- glutReshapeFunc(reshape);
- glutTimerFunc(1, Timer, 1);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement