fork download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. static constexpr std::double_t PI = std::acos(-1.0);
  6. static constexpr std::size_t SIZE_X = 100;
  7. static constexpr std::size_t SIZE_Y = 32;
  8. static constexpr std::double_t STEP = 0.01;
  9. static constexpr std::double_t MAX = PI*2.0;
  10.  
  11. int main()
  12. {
  13. std::cout << "Happy Mother's Day!\n";
  14.  
  15. bool grid[SIZE_X][SIZE_Y] {};
  16.  
  17. std::double_t xmin {}, xmax {}, ymin {}, ymax {};
  18.  
  19. using point_t = std::pair<std::double_t, std::double_t>;
  20. std::vector<point_t> points;
  21. points.reserve(static_cast<std::size_t>(MAX/STEP));
  22.  
  23. for(std::double_t t {}; t < MAX; t += STEP)
  24. {
  25. "http://mathworld"".""wolfram"".""com/HeartCurve.html";
  26. std::double_t x
  27. = 16.0 * std::pow(std::sin(t), 3);
  28. std::double_t y
  29. = 13.0 * std::cos(t)
  30. - 5.0 * std::cos(t * 2.0)
  31. - 2.0 * std::cos(t * 3.0)
  32. - std::cos(t * 4.0);
  33.  
  34. xmin = std::fmin(xmin, x);
  35. xmax = std::fmax(xmax, x);
  36. ymin = std::fmin(ymin, y);
  37. ymax = std::fmax(ymax, y);
  38.  
  39. points.emplace_back(x, y);
  40. }
  41.  
  42. std::double_t const xscale = +(xmax - xmin);
  43. std::double_t const yscale = -(ymax - ymin);
  44.  
  45. for(auto const &p : points)
  46. {
  47. std::double_t x = ((p.first - xmin) / xscale) * SIZE_X + 0.5;
  48. std::double_t y = ((p.second - ymax) / yscale) * SIZE_Y + 0.5;
  49.  
  50. if(x < 0.0) x = 0.0;
  51. if(x >= SIZE_X) x = SIZE_X - 1;
  52. if(y < 0.0) y = 0.0;
  53. if(y >= SIZE_Y) y = SIZE_Y - 1;
  54.  
  55. grid[static_cast<std::size_t>(x)][static_cast<std::size_t>(y)] = true;
  56. }
  57.  
  58. for(std::size_t y = 0; y < SIZE_Y; ++y)
  59. {
  60. for(std::size_t x = 0; x < SIZE_X; ++x)
  61. {
  62. std::cout << (grid[x][y]? '#' : '`');
  63. }
  64. std::cout << '\n';
  65. }
  66. }
  67.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Happy Mother's Day!
``````````````````################`````````````````````````````````#################````````````````
````````````######````````````````######`````````````````````######````````````````######```````````
````````####```````````````````````````####``````````````#####```````````````````````````####```````
``````###``````````````````````````````````###`````````###``````````````````````````````````###`````
```###```````````````````````````````````````###`````###```````````````````````````````````````##```
``##```````````````````````````````````````````##```##```````````````````````````````````````````##`
`##`````````````````````````````````````````````##`##`````````````````````````````````````````````##
##```````````````````````````````````````````````###```````````````````````````````````````````````#
#`````````````````````````````````````````````````#````````````````````````````````````````````````#
#``````````````````````````````````````````````````````````````````````````````````````````````````#
#``````````````````````````````````````````````````````````````````````````````````````````````````#
`#`````````````````````````````````````````````````````````````````````````````````````````````````#
`##```````````````````````````````````````````````````````````````````````````````````````````````##
``###```````````````````````````````````````````````````````````````````````````````````````````###`
````##`````````````````````````````````````````````````````````````````````````````````````````##```
``````##`````````````````````````````````````````````````````````````````````````````````````##`````
````````###````````````````````````````````````````````````````````````````````````````````##```````
``````````###```````````````````````````````````````````````````````````````````````````###`````````
`````````````###`````````````````````````````````````````````````````````````````````####```````````
```````````````####```````````````````````````````````````````````````````````````###```````````````
```````````````````###`````````````````````````````````````````````````````````####`````````````````
`````````````````````####```````````````````````````````````````````````````###`````````````````````
`````````````````````````####```````````````````````````````````````````####````````````````````````
````````````````````````````####`````````````````````````````````````####```````````````````````````
````````````````````````````````###```````````````````````````````####``````````````````````````````
```````````````````````````````````###`````````````````````````###``````````````````````````````````
``````````````````````````````````````###```````````````````###`````````````````````````````````````
`````````````````````````````````````````###`````````````###````````````````````````````````````````
```````````````````````````````````````````###`````````###``````````````````````````````````````````
`````````````````````````````````````````````###`````###````````````````````````````````````````````
```````````````````````````````````````````````###`###``````````````````````````````````````````````
`````````````````````````````````````````````````###````````````````````````````````````````````````