Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <unistd.h>
  4.  
  5. using namespace std;
  6. int main() {
  7.     float N=21, x0=5, y0=5, s=100, r=4;
  8.     float vx = 1.5, vy = 2.5 ;
  9.     char c = 'a';
  10.     for (int t=0; t<=s; t++){
  11.       for (int i=0; i<=N; i++) {
  12.         for (int j=0; j<=N; j++) {
  13.             int CX0 = (int) x0;
  14.             int CY0 = (int) y0;
  15.             int d2=(j-CX0)*(j-CX0)+(i-CY0)*(i-CY0);
  16.             if (d2<=r*r) {
  17.                 cout<< c <<" ";
  18.             }
  19.             else if (i==0 || i==N || j==0 || j==N){
  20.                 cout<<"* ";
  21.             }
  22.             else {
  23.                 cout<<"  ";
  24.             }
  25.         }
  26.  
  27.         cout<<endl;
  28.     }
  29.       x0 += vx;
  30.       y0 += vy;
  31.       if (x0 + r >= N - 1) {
  32.           vx = -vx;
  33.           //int circle_r = x0 + r;
  34.           //int field_r  = N - 1;
  35.           //int d = circle_r - field_r;
  36.           x0 = N - 1 - r;
  37.           //x0 -= d;
  38.       }
  39.       if (y0 + r >= N - 1) {
  40.           vy = -vy;
  41.           //int circle_b = y0 + r;
  42.           //int field_b  = N - 1;
  43.           //int d = circle_b - field_b;
  44.           y0 = N - 1 - r;
  45.           //y0 -= d;
  46.       }
  47.       if (x0 - r <= 0) {
  48.           vx = -vx;
  49.           x0 = r + 1;
  50.           //x0 -= x0 - r - 1;
  51.       }
  52.       if (y0 - r <= 0) {
  53.          vy = -vy;
  54.          //int circle_t = y0 - r;
  55.          //int field_t  = 0;
  56.          //int d = circle_t - field_t;
  57.          y0 = r + 1;
  58.          //y0 -= d - 1;
  59.       }
  60.       c = (c + 1)%10 + 'a';
  61.       cout << "\033[u";
  62.       sleep(1);
  63.   }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement