Advertisement
MaxObznyi

Curve

Apr 11th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6. namespace OboznyiMaksymCurve {
  7. string header = "<html> \n"
  8. " <head> \n"
  9. " <title>Lab about random generator</title>\n"
  10. " </head> \n"
  11. " <body> \n"
  12. " <h1>by Maksym Oboznyi, K-16, 09.04.2021</h1> \n";
  13.  
  14. string footer = " </body> \n"
  15. "</html>\n";
  16.  
  17. string table_header = " <center>\n"
  18. " <h1> RESULT </h1>\n"
  19. " <table border=\"0\">\n";
  20.  
  21.  
  22. string table_footer = " </table>\n"
  23. " </center>\n";
  24.  
  25. double a[1000][1000];
  26.  
  27. int n, m;
  28. int x = 100, y = 100;
  29. vector<pair<int, int> > ans;
  30.  
  31. int pr(int x) {
  32. return (x + 3) % 4;
  33. }
  34.  
  35. int nxt(int x) {
  36. return (x + 1) % 4;
  37. }
  38.  
  39. void up() {
  40. x--;
  41. ans.push_back({x, y});
  42. a[x][y] = '#';
  43. x--;
  44.  
  45. ans.push_back({x, y});
  46. a[x][y] = '#';
  47. x--;
  48. }
  49. void down() {
  50. x++;
  51.  
  52. ans.push_back({x, y});
  53. a[x][y] = '#';
  54. x++;
  55. ans.push_back({x, y});
  56. a[x][y] = '#';
  57. x++;
  58. }
  59.  
  60. void lft() {
  61. y--;
  62. ans.push_back({x, y});
  63. a[x][y] = '#';
  64. y--;
  65. ans.push_back({x, y});
  66. a[x][y] = '#';
  67. y--;
  68. }
  69.  
  70. void rght() {
  71. y++;
  72. ans.push_back({x, y});
  73. a[x][y] = '#';
  74. y++;
  75. ans.push_back({x, y});
  76. a[x][y] = '#';
  77. y++;
  78. }
  79.  
  80.  
  81. void f(int lvl, int type, int cw) {
  82. if (lvl == 0) {
  83. ans.push_back({x, y});
  84. a[x][y] = '#';
  85. return;
  86. }
  87. if (cw) {
  88. f(lvl - 1, nxt(type), cw ^ 1);
  89.  
  90. switch (type){
  91. case 0:
  92. down();
  93. break;
  94. case 1:
  95. lft();
  96. break;
  97. case 2:
  98. up();
  99. break;
  100. case 3:
  101. rght();
  102. break;
  103. }
  104.  
  105. f(lvl - 1, type, cw);
  106.  
  107. switch (type){
  108. case 0:
  109. lft();
  110. break;
  111. case 1:
  112. up();
  113. break;
  114. case 2:
  115. rght();
  116. break;
  117. case 3:
  118. down();
  119. break;
  120. }
  121. f(lvl - 1, type, cw);
  122. switch (type){
  123. case 0:
  124. up();
  125. break;
  126. case 1:
  127. rght();
  128. break;
  129. case 2:
  130. down();
  131. break;
  132. case 3:
  133. lft();
  134. break;
  135. }
  136.  
  137. f(lvl - 1, pr(type), cw ^ 1);
  138. } else {
  139.  
  140. f(lvl - 1, pr(type), cw ^ 1);
  141. switch (type){
  142. case 0:
  143. down();
  144. break;
  145. case 1:
  146. lft();
  147. break;
  148. case 2:
  149. up();
  150. break;
  151. case 3:
  152. rght();
  153. break;
  154. }
  155.  
  156. f(lvl - 1, type, cw);
  157. switch (type){
  158. case 0:
  159. rght();
  160. break;
  161. case 1:
  162. down();
  163. break;
  164. case 2:
  165. lft();
  166. break;
  167. case 3:
  168. up();
  169. break;
  170. }
  171.  
  172. f(lvl - 1, type, cw);
  173. switch (type){
  174. case 0:
  175. up();
  176. break;
  177. case 1:
  178. rght();
  179. break;
  180. case 2:
  181. down();
  182. break;
  183. case 3:
  184. lft();
  185. break;
  186. }
  187.  
  188. f(lvl - 1, nxt(type), cw ^ 1);
  189. }
  190. }
  191.  
  192. void print() {
  193. ofstream cout("output.html");
  194. cout << header << table_header;
  195. double color = 0xFF;
  196. double step = color / ans.size();
  197. for (auto [x, y] : ans)
  198. a[x][y] = color, color -= step;
  199. for (int i = 0; i < n; i++) {
  200. cout << " <tr>\n";
  201. for (int j = 0; j < m; j++)
  202. if (a[i][j] != -1)
  203. cout << " <td style = \"font-size: 24px; color: white; width: 20px; height: 20px\"bgcolor=\""
  204. << setw(2) << setfill('0') << hex << min((int)a[i][j], 0xFF) << "0000\"></td>\n";
  205. else
  206. cout << " <td style = \"font-size: 24px; color: white; width: 20px; height: 20px\"bgcolor=\"FFFFFF\"></td>\n";
  207. cout << " </tr>\n";
  208. }
  209. cout << table_footer << footer;
  210. }
  211.  
  212. void run() {
  213. int lvl, type, cw;
  214. while (1) {
  215.  
  216. cout << "Enter level(from 1 to 6):";
  217. cin >> lvl;
  218. if (lvl < 1 || lvl > 6)
  219. cout << "Incorrect level\n";
  220. else
  221. break;
  222. }
  223. while (1) {
  224. cout << "Enter type(from 0 to 3):";
  225. cin >> type;
  226. if (type < 0 || type > 3)
  227. cout << "Incorrect type\n";
  228. else
  229. break;
  230. }
  231. while (1) {
  232. cout << "Is clockwise(1/0)";
  233. cin >> cw;
  234. if (cw < 0 || cw > 1)
  235. cout << "Incorrect input\n";
  236. else
  237. break;
  238. }
  239. f(lvl, type, cw);
  240.  
  241. for (int i = 0; i < 1000; i++)
  242. for (int j = 0; j < 1000; j++)
  243. a[i][j] = -1;
  244.  
  245. int mnx = 1000, mny = 1000, mxx = 0, mxy = 0;
  246. for (auto [x, y] : ans) {
  247. mnx = min(mnx, x);
  248. mxx = max(mxx, x);
  249. mny = min(mny, y);
  250. mxy = max(mxy, y);
  251. }
  252. for (auto &[x, y] : ans)
  253. x -= mnx, y -= mny;
  254. n = mxx - mnx + 1;
  255. m = mxy - mny + 1;
  256. print();
  257. }
  258. }
  259. int main()
  260. {
  261.  
  262. OboznyiMaksymCurve::run();
  263. return 0;
  264. }
  265.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement