Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <vector>
  4. #include <gl/glut.h>
  5.  
  6. #define intensivity 1
  7.  
  8. using namespace std;
  9.  
  10. GLfloat WinW = 800, WinH = 600;
  11.  
  12. int gen[] = { -1, 0, 1 };
  13.  
  14. class SnowFlake {
  15. public:
  16. GLfloat x;
  17. GLfloat y;
  18. GLfloat direction;
  19. bool fell;
  20. SnowFlake();
  21. };
  22.  
  23. SnowFlake::SnowFlake() {
  24. x = rand() % int(WinW);
  25. y = WinH;
  26. direction = gen[rand() % 3];
  27. fell = false;
  28. }
  29.  
  30. vector<SnowFlake> SnowFlakes;
  31.  
  32. void draw() {
  33. glClear(GL_COLOR_BUFFER_BIT);
  34. glLoadIdentity();
  35. glPushMatrix();
  36. glColor3f(1, 1, 1);
  37. glBegin(GL_POINTS);
  38. for (unsigned int i = 0; i < SnowFlakes.size(); i++) {
  39. glVertex2f(SnowFlakes[i].x, SnowFlakes[i].y);
  40. }
  41. glEnd();
  42. glPopMatrix();
  43. glutSwapBuffers();
  44. }
  45.  
  46. void Timer(int value) {
  47. int n = 0;
  48. for (unsigned int i = 0; i < SnowFlakes.size(); i++) {
  49. if (SnowFlakes[i].y > n) {
  50. SnowFlakes[i].y--;
  51. SnowFlakes[i].x += SnowFlakes[i].direction;
  52. SnowFlakes[i].direction = gen[rand() % 3];
  53.  
  54. }
  55. if (SnowFlakes[i].y <= n) {
  56. SnowFlakes[i].direction = gen[rand() % 3];
  57. SnowFlakes[i].x += SnowFlakes[i].direction;
  58. n++;
  59. }
  60.  
  61.  
  62. }
  63. for (int i = 0; i < intensivity; i++) SnowFlakes.push_back(SnowFlake());
  64. glutPostRedisplay();
  65. glutTimerFunc(3, Timer, 1);
  66. }
  67.  
  68. void reshape(GLsizei WW, GLsizei WH) {
  69. glViewport(0, 0, WW, WH);
  70. glMatrixMode(GL_PROJECTION);
  71. glLoadIdentity();
  72. glOrtho(0, WinW, 0, WinH, 0, 1);
  73. glMatrixMode(GL_MODELVIEW);
  74. glLoadIdentity();
  75. }
  76.  
  77. int main(int argc, char** argv) {
  78. srand(time(NULL));
  79. for (int i = 0; i < intensivity; i++) {
  80. SnowFlakes.push_back(SnowFlake());
  81. }
  82. glutInit(&argc, argv);
  83. glutInitWindowSize(WinW, WinH);
  84. glutInitWindowPosition(100, 100);
  85. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  86. glutCreateWindow("RGR 12");
  87. glutDisplayFunc(draw);
  88. glutReshapeFunc(reshape);
  89. glutTimerFunc(1, Timer, 1);
  90. glutMainLoop();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement