Advertisement
Guest User

kfadrat vol 3

a guest
Jan 21st, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4. #include <Windows.h>
  5. using namespace std;
  6.  
  7. struct punkt {
  8.     double x = 0;
  9.     double y = 0;
  10. };
  11.  
  12. int w = 60;
  13. int h = 40;
  14.  
  15. void rysuj(punkt *t) {
  16.     HANDLE handle = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  17.     DWORD test;
  18.     wchar_t * buffer = new wchar_t[w * h];
  19.     SetConsoleActiveScreenBuffer(handle);
  20.     for (int i = 0; i < w * h; i++) {
  21.         buffer[i] = ' ';
  22.     }
  23.     int x = t->x * h;
  24.     int y = t->y * w;
  25.     buffer[x + y * h] = 'o';
  26.     WriteConsoleOutputCharacter(handle, buffer, w * h, { 0,0 }, &test);
  27.     Sleep(20);
  28. }
  29.  
  30. int main()
  31. {
  32.     punkt k;
  33.     k.x = 0.5;
  34.     k.y = 0.5;
  35.     float ruch_y = 0.03;
  36.     float ruch_x = 0.02;
  37.         for (int i = 0; i <= 100; i++) {
  38.             if (k.x >= 1 || k.x <= 0)
  39.                 ruch_x *= -1;
  40.             if (k.y >= 1 || k.y <= 0)
  41.                 ruch_y *= -1;
  42.             k.x += ruch_x;
  43.             k.y += ruch_y;
  44.             rysuj(&k);
  45.         }
  46.     std::cin.get();
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement