Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <climits>
- #include <fstream>
- struct Color {
- int r;
- int g;
- int b;
- unsigned int color;
- };
- struct ArrayInfo {
- Color **Array2;
- int Length;
- int LastIndex;
- };
- Color* wavelengthToDecoColour(unsigned int wl) // function from TPT source code
- {
- int x = 0;
- int colg = 0;
- int colb = 0;
- int colr = 0;
- for (x = 0; x<12; x++) {
- colr += (wl >> (x + 18)) & 1;
- colb += (wl >> x) & 1;
- }
- for (x = 0; x<12; x++)
- colg += (wl >> (x + 9)) & 1;
- x = 624 / (colr + colg + colb + 1);
- if (0>0 && 0 <= 4) //replaced element life with 0, because default FILT life is 0
- int cola = 127 + 0 * 30;
- else
- int cola = 127;
- colr *= x;
- colg *= x;
- colb *= x;
- if (colr > 255) colr = 255;
- else if (colr < 0) colr = 0;
- if (colg > 255) colg = 255;
- else if (colg < 0) colg = 0;
- if (colb > 255) colb = 255;
- else if (colb < 0) colb = 0;
- return new Color{ colr,colg,colb,wl };
- }
- bool IsColorExist(ArrayInfo* a, Color* c) {
- for (size_t i = 0; i < a->LastIndex; i++)
- {
- if (a->Array2[i]->r == c->r) {
- if (a->Array2[i]->g == c->g) {
- if (a->Array2[i]->b == c->b) {
- return true;
- }
- }
- }
- }
- return false;
- }
- void InsertColor(ArrayInfo* a, Color* c) {
- if (!IsColorExist(a, c)) {
- a->Array2[a->LastIndex] = c;
- a->LastIndex++;
- }
- else
- {
- delete c;
- }
- }
- int main()
- {
- ArrayInfo* a = new ArrayInfo();
- a->Length = 5000; //How many colors to expect
- a->LastIndex = 0;
- a->Array2 = new Color*[a->Length];
- unsigned int i = 1;
- while (a->LastIndex < a->Length - 1 && i < UINT_MAX) {
- InsertColor(a, wavelengthToDecoColour(i));
- i++;
- }
- std::ofstream outfile;
- outfile.open("output.txt", std::ios_base::app);
- for (size_t i = 0; i < a->LastIndex; i++)
- {
- outfile << a->Array2[i]->color << " " << a->Array2[i]->r << " " << a->Array2[i]->g << " " << a->Array2[i]->b << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement