Advertisement
Guest User

Untitled

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