Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <unistd.h>
  4. #include <time.h>
  5. #include <getopt.h>
  6. #include "color.h"
  7. using namespace std;
  8. #define N 25
  9. #define M 60
  10. void board(int x, int y, int cc)
  11. {
  12. int i, j;
  13. for (i = 0; i <= N; i++) {
  14. for (j = 0; j <= M; j++)
  15. if (i == y && j == x) {
  16. switch (cc) {
  17. case 1:
  18. cout << color::red << '*';
  19. break;
  20. case 2:
  21. cout << color::green << '*';
  22. break;
  23. case 3:
  24. cout << color::yellow << '*';
  25. break;
  26. case 4:
  27. cout << color::blue << '*';
  28. break;
  29. case 5:
  30. cout << color::magenta << '*';
  31. break;
  32. case 6:
  33. cout << color::cyan << '*';
  34. break;
  35. case 7:
  36. cout << color::white << '*';
  37. break;
  38. default:
  39. cout << color::yellow << '*';
  40. }
  41. }
  42. else
  43. cout << ' ';
  44. cout << endl;
  45. }
  46. return;
  47. }
  48. void gravity(int cc, int u)
  49. {
  50. srand(time(NULL));
  51. int x = rand() % M;
  52. int dx = 1;
  53. int y = rand() % N;
  54. int dy = 0;
  55. int v;
  56. int i;
  57. 0 while (true)
  58. {
  59. cout << string(80, 'n');
  60. v = .8 * i;
  61. dy = dy + v;
  62. if (x == 0 || x == M) {
  63. dx *= -1;
  64. }
  65. if (dy <= 0) {
  66. i = 2;
  67. }
  68. y = y + dy;
  69. if (y >= N) {
  70. y = N;
  71. dy = dy - (dy / 2);
  72. dy *= -1;
  73. i = 2;
  74. }
  75. board(x += dx, y, cc);
  76. usleep(u);
  77. i++;
  78. }
  79. }
  80. int main(int argc, char** argv)
  81. {
  82. int option;
  83. int u;
  84. bool colorcheck = false;
  85. bool speedcheck = false;
  86. int cc = 3;
  87. int x = 1;
  88. float k = 1;
  89. int v;
  90. int y = 1;
  91. int dy = 0;
  92. int a, j;
  93. int i = 1;
  94. while ((option = getopt(argc, argv, "csh")) != -1) {
  95. switch (option) {
  96. case 'c':
  97. colorcheck = true;
  98. break;
  99. case 's':
  100. speedcheck = true;
  101. break;
  102. case 'h':
  103. cout << endl
  104. << "Welcome to Parameterized Gravity Animation" << endl
  105. << endl;
  106. cout << "Use '-c' to set the color of the ball. Enter the number that corresponds to the desired color." << endl;
  107. cout << "All colors included in color.h excluding are supported." << endl;
  108. cout << "1. red n 2. green n 3. yellow n 4. blue n 5. magenta n 6. cyan n 7. white" << endl
  109. << endl;
  110. cout << "Use '-s' to set a speed multiplier. Enter a floating point number when prompted." << endl;
  111. cout << "1 is the recommended (realistic) speed." << endl
  112. << endl;
  113. break;
  114. }
  115. }
  116. if (speedcheck == true) {
  117. cout << "Please input speed multiplier: " << endl;
  118. cin >> k;
  119. }
  120. if (speedcheck == false) {
  121. k = 1;
  122. }
  123. u = 250000 * (1 / k);
  124. if (colorcheck == true) {
  125. cout << "Please choose a color by entering an integer between 1 and 7: ";
  126. cin >> cc;
  127. }
  128. gravity(cc, u);
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement