Guest User

Name Color Generator

a guest
Sep 28th, 2018
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <regex>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. class ColorName {
  8.    
  9.     private:
  10.        
  11.         const string skip   = "^(?:anonymous|анонимус)$";
  12.         int   color_mask    = 0;
  13.         char  hex_chars[17] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  14.        
  15.     public:
  16.        
  17.         string from(string name) {
  18.            
  19.             if (regex_match(name, regex(skip))) {
  20.                 return "transparent";
  21.             }
  22.             const int length = name.length();
  23.             char name_charCodeAt[length];
  24.            
  25.             strcpy(name_charCodeAt, name.c_str());
  26.             double mask = color_mask % 0x1f4b;
  27.            
  28.             stringstream output;
  29.             output << "#";
  30.            
  31.             for (int i = 0; i < 6; i++) {
  32.                
  33.                 for (int c = 0; c < length; c++) {
  34.                     double b = 0.02519603282416938 * (mask + name_charCodeAt[c]),
  35.                            a = (b - (uint)b) * (uint)b;
  36.                         mask = (uint)a + ( a - (uint)a) * 0x100000000;
  37.                 }
  38.                 output << hex_chars[ (uint)((uint)mask * 2.3283064365386963e-10 * 16) ];
  39.             }
  40.            
  41.             return output.str();
  42.         }
  43.        
  44.         ColorName(string seed) {
  45.            
  46.             const int length = seed.length();
  47.             char seed_charCodeAt[length];
  48.            
  49.             strcpy(seed_charCodeAt, seed.c_str());
  50.             color_mask = 0x4872d1e6;
  51.            
  52.             for (int i = 0; i < length; i++) {
  53.                 color_mask = (color_mask << 1) + seed_charCodeAt[i];
  54.             }
  55.             color_mask = abs(color_mask);
  56.         }
  57. };
  58.  
  59. int main (int argc, char** argv) {
  60.     ColorName color("ЧgЖ0CгтWйwРstлХИyхoязХи9МymЫzLмz");
  61.    
  62.     for (int i = 1; i < argc; i++) {
  63.         cout << color.from(argv[i]) << " generate from `\033[1;41m" << argv[i] << "\033[0m`\n";
  64.     }
  65.     return 0;
  66. }
Add Comment
Please, Sign In to add comment