Guest User

Untitled

a guest
Oct 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <cmath>
  5.  
  6. char buf[32][32];
  7.  
  8. void clearBuf()
  9. {
  10. for (int i = 0; i < 32; i++)
  11. for (int j = 0; j < 32; j++)
  12. {
  13. buf[i][j] = '.';
  14. }
  15. }
  16.  
  17. void drawLine(int y1, int x1, int y2, int x2) {
  18. const int deltaX = abs(x2 - x1);
  19. const int deltaY = abs(y2 - y1);
  20. const int signX = x1 < x2 ? 1 : -1;
  21. const int signY = y1 < y2 ? 1 : -1;
  22. //
  23. int error = deltaX - deltaY;
  24. //
  25. buf[x2][y2] = '#';
  26. while(x1 != x2 || y1 != y2)
  27. {
  28. buf[x1][y1] = '#';
  29. const int error2 = error * 2;
  30. //
  31. if(error2 > -deltaY)
  32. {
  33. error -= deltaY;
  34. x1 += signX;
  35. }
  36. if(error2 < deltaX)
  37. {
  38. error += deltaX;
  39. y1 += signY;
  40. }
  41. }
  42.  
  43. }
  44.  
  45. void display()
  46. {
  47. for (int i = 0; i < 32; i++)
  48. {
  49. for (int j = 0; j < 32; j++)
  50. {
  51. std::cout << buf[i][j] << " ";
  52. }
  53. std::cout << std::endl;
  54. }
  55. }
  56. int main()
  57. {
  58.  
  59. clearBuf();
  60. drawLine(0, 31, 31/2, 0);
  61. drawLine(31/2, 0, 31, 31);
  62. drawLine(31, 31, 0, 31);
  63.  
  64. drawLine(8, 16, 23, 16);
  65. drawLine(8, 16, 31/2, 31);
  66. drawLine(23, 16, 32/2, 31);
  67.  
  68. display();
  69. }
Add Comment
Please, Sign In to add comment