Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <unistd.h>
- #include <time.h>
- #include <getopt.h>
- #include "color.h"
- using namespace std;
- #define N 25
- #define M 60
- void board(int x, int y, int cc)
- {
- int i, j;
- for (i = 0; i <= N; i++) {
- for (j = 0; j <= M; j++)
- if (i == y && j == x) {
- switch (cc) {
- case 1:
- cout << color::red << '*';
- break;
- case 2:
- cout << color::green << '*';
- break;
- case 3:
- cout << color::yellow << '*';
- break;
- case 4:
- cout << color::blue << '*';
- break;
- case 5:
- cout << color::magenta << '*';
- break;
- case 6:
- cout << color::cyan << '*';
- break;
- case 7:
- cout << color::white << '*';
- break;
- default:
- cout << color::yellow << '*';
- }
- }
- else
- cout << ' ';
- cout << endl;
- }
- return;
- }
- void gravity(int cc, int u)
- {
- srand(time(NULL));
- int x = rand() % M;
- int dx = 1;
- int y = rand() % N;
- int dy = 0;
- int v;
- int i;
- 0 while (true)
- {
- cout << string(80, 'n');
- v = .8 * i;
- dy = dy + v;
- if (x == 0 || x == M) {
- dx *= -1;
- }
- if (dy <= 0) {
- i = 2;
- }
- y = y + dy;
- if (y >= N) {
- y = N;
- dy = dy - (dy / 2);
- dy *= -1;
- i = 2;
- }
- board(x += dx, y, cc);
- usleep(u);
- i++;
- }
- }
- int main(int argc, char** argv)
- {
- int option;
- int u;
- bool colorcheck = false;
- bool speedcheck = false;
- int cc = 3;
- int x = 1;
- float k = 1;
- int v;
- int y = 1;
- int dy = 0;
- int a, j;
- int i = 1;
- while ((option = getopt(argc, argv, "csh")) != -1) {
- switch (option) {
- case 'c':
- colorcheck = true;
- break;
- case 's':
- speedcheck = true;
- break;
- case 'h':
- cout << endl
- << "Welcome to Parameterized Gravity Animation" << endl
- << endl;
- cout << "Use '-c' to set the color of the ball. Enter the number that corresponds to the desired color." << endl;
- cout << "All colors included in color.h excluding are supported." << endl;
- cout << "1. red n 2. green n 3. yellow n 4. blue n 5. magenta n 6. cyan n 7. white" << endl
- << endl;
- cout << "Use '-s' to set a speed multiplier. Enter a floating point number when prompted." << endl;
- cout << "1 is the recommended (realistic) speed." << endl
- << endl;
- break;
- }
- }
- if (speedcheck == true) {
- cout << "Please input speed multiplier: " << endl;
- cin >> k;
- }
- if (speedcheck == false) {
- k = 1;
- }
- u = 250000 * (1 / k);
- if (colorcheck == true) {
- cout << "Please choose a color by entering an integer between 1 and 7: ";
- cin >> cc;
- }
- gravity(cc, u);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement