-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
68 lines (59 loc) · 2.67 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/******************************************************************************
* Copyright (c) 2015 Artur Eganyan
*
* This software is provided "AS IS", WITHOUT ANY WARRANTY, express or implied.
******************************************************************************/
#include "randomcolor.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <iomanip>
// Create and open html with all color ranges
int main( int argc, char** argv )
{
RandomColor randomColor;
const char* luminosityNames[] = {"Dark", "Normal", "Light", "Bright", "Random"};
const char* colorNames[] = {
"Red", "RedOrange", "Orange", "OrangeYellow", "Yellow",
"YellowGreen", "Green", "GreenCyan", "Cyan", "CyanBlue",
"Blue", "BlueMagenta", "Magenta", "MagentaPink", "Pink",
"PinkRed", "RandomHue", "BlackAndWhite", "Brown"
};
std::fstream file("example.html", std::fstream::out | std::fstream::trunc);
if (file.fail()) {
std::cerr << "Can not open example.html" << std::endl;
return EXIT_FAILURE;
}
auto addRow = [&]( RandomColor::Color color, RandomColor::Luminosity luminosity )
{
// This resets the random generator for each row, so that rows will
// contain identically distributed colors. To generate random rows,
// it should be commented out.
randomColor.setSeed(123); // This value is just for test (not even a prime)
file << "<tr>";
file << "<td style='width:100px; text-align:right;'>" << luminosityNames[int(luminosity)] << "  </td>";
file << "<td style='line-height:0px;'>";
for (int i = 0; i < 10; ++ i) {
file << "<div style='width:50px; height:50px; margin:2px; display:inline-block; background-color:#"
<< std::hex << std::setw(6) << std::setfill('0')
<< randomColor.generate(color, luminosity)
<< "'></div>";
}
file << "</td></tr>";
};
file << "<!DOCTYPE html><html><body>";
file << "<table style='width:750px; margin:auto;'>";
for (int c = RandomColor::Red; c <= RandomColor::Brown; ++ c) {
file << "<tr><th colspan='2' style='text-align:center;'>" << colorNames[c] << "</th></tr>";
addRow((RandomColor::Color)c, RandomColor::Light);
addRow((RandomColor::Color)c, RandomColor::Normal);
addRow((RandomColor::Color)c, RandomColor::Dark);
addRow((RandomColor::Color)c, RandomColor::Bright);
addRow((RandomColor::Color)c, RandomColor::RandomLuminosity);
file << "<tr style='height:50px;'></tr>";
}
file << "</table></body></html>";
file.close();
system("example.html");
return EXIT_SUCCESS;
}