Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- namespace OboznyiMaksymCurve {
- string header = "<html> \n"
- " <head> \n"
- " <title>Lab about random generator</title>\n"
- " </head> \n"
- " <body> \n"
- " <h1>by Maksym Oboznyi, K-16, 09.04.2021</h1> \n";
- string footer = " </body> \n"
- "</html>\n";
- string table_header = " <center>\n"
- " <h1> RESULT </h1>\n"
- " <table border=\"0\">\n";
- string table_footer = " </table>\n"
- " </center>\n";
- double a[1000][1000];
- int n, m;
- int x = 100, y = 100;
- vector<pair<int, int> > ans;
- int pr(int x) {
- return (x + 3) % 4;
- }
- int nxt(int x) {
- return (x + 1) % 4;
- }
- void up() {
- x--;
- ans.push_back({x, y});
- a[x][y] = '#';
- x--;
- ans.push_back({x, y});
- a[x][y] = '#';
- x--;
- }
- void down() {
- x++;
- ans.push_back({x, y});
- a[x][y] = '#';
- x++;
- ans.push_back({x, y});
- a[x][y] = '#';
- x++;
- }
- void lft() {
- y--;
- ans.push_back({x, y});
- a[x][y] = '#';
- y--;
- ans.push_back({x, y});
- a[x][y] = '#';
- y--;
- }
- void rght() {
- y++;
- ans.push_back({x, y});
- a[x][y] = '#';
- y++;
- ans.push_back({x, y});
- a[x][y] = '#';
- y++;
- }
- void f(int lvl, int type, int cw) {
- if (lvl == 0) {
- ans.push_back({x, y});
- a[x][y] = '#';
- return;
- }
- if (cw) {
- f(lvl - 1, nxt(type), cw ^ 1);
- switch (type){
- case 0:
- down();
- break;
- case 1:
- lft();
- break;
- case 2:
- up();
- break;
- case 3:
- rght();
- break;
- }
- f(lvl - 1, type, cw);
- switch (type){
- case 0:
- lft();
- break;
- case 1:
- up();
- break;
- case 2:
- rght();
- break;
- case 3:
- down();
- break;
- }
- f(lvl - 1, type, cw);
- switch (type){
- case 0:
- up();
- break;
- case 1:
- rght();
- break;
- case 2:
- down();
- break;
- case 3:
- lft();
- break;
- }
- f(lvl - 1, pr(type), cw ^ 1);
- } else {
- f(lvl - 1, pr(type), cw ^ 1);
- switch (type){
- case 0:
- down();
- break;
- case 1:
- lft();
- break;
- case 2:
- up();
- break;
- case 3:
- rght();
- break;
- }
- f(lvl - 1, type, cw);
- switch (type){
- case 0:
- rght();
- break;
- case 1:
- down();
- break;
- case 2:
- lft();
- break;
- case 3:
- up();
- break;
- }
- f(lvl - 1, type, cw);
- switch (type){
- case 0:
- up();
- break;
- case 1:
- rght();
- break;
- case 2:
- down();
- break;
- case 3:
- lft();
- break;
- }
- f(lvl - 1, nxt(type), cw ^ 1);
- }
- }
- void print() {
- ofstream cout("output.html");
- cout << header << table_header;
- double color = 0xFF;
- double step = color / ans.size();
- for (auto [x, y] : ans)
- a[x][y] = color, color -= step;
- for (int i = 0; i < n; i++) {
- cout << " <tr>\n";
- for (int j = 0; j < m; j++)
- if (a[i][j] != -1)
- cout << " <td style = \"font-size: 24px; color: white; width: 20px; height: 20px\"bgcolor=\""
- << setw(2) << setfill('0') << hex << min((int)a[i][j], 0xFF) << "0000\"></td>\n";
- else
- cout << " <td style = \"font-size: 24px; color: white; width: 20px; height: 20px\"bgcolor=\"FFFFFF\"></td>\n";
- cout << " </tr>\n";
- }
- cout << table_footer << footer;
- }
- void run() {
- int lvl, type, cw;
- while (1) {
- cout << "Enter level(from 1 to 6):";
- cin >> lvl;
- if (lvl < 1 || lvl > 6)
- cout << "Incorrect level\n";
- else
- break;
- }
- while (1) {
- cout << "Enter type(from 0 to 3):";
- cin >> type;
- if (type < 0 || type > 3)
- cout << "Incorrect type\n";
- else
- break;
- }
- while (1) {
- cout << "Is clockwise(1/0)";
- cin >> cw;
- if (cw < 0 || cw > 1)
- cout << "Incorrect input\n";
- else
- break;
- }
- f(lvl, type, cw);
- for (int i = 0; i < 1000; i++)
- for (int j = 0; j < 1000; j++)
- a[i][j] = -1;
- int mnx = 1000, mny = 1000, mxx = 0, mxy = 0;
- for (auto [x, y] : ans) {
- mnx = min(mnx, x);
- mxx = max(mxx, x);
- mny = min(mny, y);
- mxy = max(mxy, y);
- }
- for (auto &[x, y] : ans)
- x -= mnx, y -= mny;
- n = mxx - mnx + 1;
- m = mxy - mny + 1;
- print();
- }
- }
- int main()
- {
- OboznyiMaksymCurve::run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement