Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int RGB_na_HSL(float R, float G, float B){
- float _R, _G, _B, H, S, L, max, min, delta;
- int i; // co jest maxem
- if (R <= 255 && R >= 0 && G <= 255 && G >= 0 && B <= 255 && B >= 0){
- _R = R / 255;
- _G = G / 255;
- _B = B / 255;
- max = _R; i = 1;
- if (_G > max) {max = _G; i = 2;}
- if (_B > max) {max = _B; i = 3;}
- min = _R;
- if (_G < min) min = _G;
- if (_B < min) min = _B;
- delta = max - min;
- // OBLICZANIE L
- L = (max + min) / 2;
- // OBLICZANIE S
- if (delta == 0) S = 0;
- else S = delta / (1 - abs(2 * L - 1));
- // OBLICZANIE H
- switch (i){
- case 1:
- H = (_G - _B) / delta;
- H = fmodf(H, 6);
- H *= 60;
- break;
- case 2:
- H = 60 * (((_B - _R) / delta) + 2);
- break;
- case 3:
- H = 60 * (((_R - _G) / delta) + 4);
- break;
- }
- // Zaokrąglenie
- cout.setf(ios::fixed);
- cout.precision(1);
- // Poprawki procentowe
- S *= 100;
- L *= 100;
- cout << "RGB(" << R << ", " << G << ", " << B << ")->HSL(" << H << "st, " << S << "%, " << L << "%)" << endl << endl;
- return 0;
- }
- else return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement