Node中的request模組與cheerio模組實現簡單爬蟲
阿新 • • 發佈:2021-01-11
技術標籤:HSL顏色空間轉RGBc++演算法c語言
全網最簡單的HSL轉RGB
H[0,360] S[0,100] L[0,100]
R[0,255] G[0,255] B[0,255]
#include <iostream>
#include "math.h"
int main(int argc, char** argv) {
int H ;
float S ;
float L ;
int *P1,*P2,*P3;
float value_A,value_B,value_C;
unsigned char mode=0;
float ratio;
int R,G,B;
int *p_buf[6][3]={
{&R,&G,&B},
{&G,&R,&B},
{&G,&B,&R},
{&B,&G,&R},
{&B,&R,&G},
{&R,&B,&G},
};
while(1)
{
printf("(ps:輸入大於360的數退出) \r\n請輸入 H:");
scanf("%d",&H);
if(H>360)
return 0;
printf("請輸入 S:");
scanf("%f",&S);
printf("請輸入 L:");
scanf("%f",&L);
if(H==360)H=0;
if(S==0)//白色
{
R = L;
G = L;
B = L;
goto end;
}
S = S/100;
L = L/100;
mode = H/60;
ratio = H/60.0-mode;
// printf("mode :%d ratio:%.2f \r\n",mode,ratio);
value_A = 255;
if(mode%2==0) value_B = 255*ratio;
else value_B = 255*(1-ratio);
value_C = 0;
// printf("A:%.2f B:%.2f C:%.2f >>>\r\n",value_A,value_B,value_C);
value_A = ((1-S)*255+value_A*S)*L;
value_B = ((1-S)*255+value_B*S)*L;
value_C = ((1-S)*255+value_C*S)*L;
// printf("A:%.2f B:%.2f C:%.2f >>>\r\n",value_A,value_B,value_C);
// value_A = value_A*L;
// value_B = value_B*L;
// value_C = value_C*L;
// printf("A:%.2f B:%.2f C:%.2f >>>\r\n",value_A,value_B,value_C);
*p_buf[mode][0]=(int)(value_A+0.5);//四捨五入
*p_buf[mode][1]=(int)(value_B+0.5);//四捨五入
*p_buf[mode][2]=(int)(value_C+0.5);//四捨五入
end:
printf("轉換出的RGB >>> R:%d G:%d B:%d\r\n\r\n",R,G,B);
}
return 0;
}