Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <regex>
- #include <cmath>
- using namespace std;
- class ColorName {
- private:
- const string skip = "^(?:anonymous|анонимус)$";
- int color_mask = 0;
- char hex_chars[17] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- public:
- string from(string name) {
- if (regex_match(name, regex(skip))) {
- return "transparent";
- }
- const int length = name.length();
- char name_charCodeAt[length];
- strcpy(name_charCodeAt, name.c_str());
- double mask = color_mask % 0x1f4b;
- stringstream output;
- output << "#";
- for (int i = 0; i < 6; i++) {
- for (int c = 0; c < length; c++) {
- double b = 0.02519603282416938 * (mask + name_charCodeAt[c]),
- a = (b - (uint)b) * (uint)b;
- mask = (uint)a + ( a - (uint)a) * 0x100000000;
- }
- output << hex_chars[ (uint)((uint)mask * 2.3283064365386963e-10 * 16) ];
- }
- return output.str();
- }
- ColorName(string seed) {
- const int length = seed.length();
- char seed_charCodeAt[length];
- strcpy(seed_charCodeAt, seed.c_str());
- color_mask = 0x4872d1e6;
- for (int i = 0; i < length; i++) {
- color_mask = (color_mask << 1) + seed_charCodeAt[i];
- }
- color_mask = abs(color_mask);
- }
- };
- int main (int argc, char** argv) {
- ColorName color("ЧgЖ0CгтWйwРstлХИyхoязХи9МymЫzLмz");
- for (int i = 1; i < argc; i++) {
- cout << color.from(argv[i]) << " generate from `\033[1;41m" << argv[i] << "\033[0m`\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment