Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <cstdio>
  2. #include <climits>
  3. #include <iostream>
  4. #include <ctime>
  5. #include <cmath>
  6. #include <graphics.h>
  7. #include <windows.h>
  8. #include <sys/time.h>
  9. #include <thread>
  10.  
  11. using namespace std;
  12.  
  13. const int width = 1000;
  14. const int height = 600;
  15.  
  16.  
  17. int func(int x) {
  18. return sin(x * 0.02) * 50;
  19. }
  20.  
  21. int random(int min, int max) {
  22. return min + rand() % (max - min);
  23. }
  24.  
  25. const int rect_count = 20;
  26.  
  27. struct rectangle
  28. {
  29. int width;
  30. int height;
  31. int x, y;
  32. } rectangles[rect_count];
  33.  
  34. int main() {
  35. initwindow(width, height);
  36. int i = 0;
  37. bool page = 0;
  38.  
  39. bool fl = 1;
  40.  
  41. srand(time(NULL));
  42. for(int i = 0; i < rect_count; i++) {
  43. rectangles[i].width = random(10, 70);
  44. rectangles[i].height = random(10, 70);
  45.  
  46. rectangles[i].x = random(0, width - rectangles[i].width);
  47. rectangles[i].y = random(0, height - rectangles[i].height);
  48. }
  49.  
  50.  
  51. while (true) {
  52. setactivepage(page = !page);
  53.  
  54. setfillstyle(SOLID_FILL, COLOR(47, 47, 47));
  55. bar(0, 0, width, height);
  56.  
  57. setfillstyle(SOLID_FILL, COLOR(255, 0, 0));
  58.  
  59.  
  60. for(int i = 0; i < rect_count; i++) {
  61. if(rectangles[i].x <= 0)
  62. rectangles[i].x += 6;
  63. rectangles[i].x += random(-5, 6);
  64. if(rectangles[i].y <= 0)
  65. rectangles[i].y += 6;
  66. rectangles[i].y += random(-5, 6);
  67.  
  68. rectangle( rectangles[i].x,
  69. rectangles[i].y,
  70. rectangles[i].x + rectangles[i].width,
  71. rectangles[i].y + rectangles[i].height);
  72. }
  73.  
  74. delay(1);
  75. setvisualpage(page);
  76. }
  77. }
Add Comment
Please, Sign In to add comment