mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-25 05:48:41 +00:00
96d4a3ecf7
Due to historical reasons, the code is in subfolder "1". With SVN removal, we place the code back and remove the annoying "1" folder.
2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
function HSV(a,b,c){0>=a&&(a=0),0>=b&&(b=0),0>=c&&(c=0),a>360&&(a=360),b>100&&(b=100),c>100&&(c=100),this.h=a,this.s=b,this.v=c}function RGB(a,b,c){0>=a&&(a=0),0>=b&&(b=0),0>=c&&(c=0),a>255&&(a=255),b>255&&(b=255),c>255&&(c=255),this.r=a,this.g=b,this.b=c}var ColorConverter={_RGBtoHSV:function(a){var d,e,f,h,i,j,c=new HSV(0,0,0);return r=a.r/255,g=a.g/255,b=a.b/255,d=Math.min(r,g,b),e=Math.max(r,g,b),f=e-d,c.v=e,0==f?(c.h=0,c.s=0):(c.s=f/e,h=((e-r)/6+f/2)/f,i=((e-g)/6+f/2)/f,j=((e-b)/6+f/2)/f,r==e?c.h=j-i:g==e?c.h=1/3+h-j:b==e&&(c.h=2/3+i-h),c.h<0&&(c.h+=1),c.h>1&&(c.h-=1)),c.h=Math.round(360*c.h),c.s=Math.round(100*c.s),c.v=Math.round(100*c.v),c},_HSVtoRGB:function(a){var b=new RGB(0,0,0),c=a.h/360,d=a.s/100,e=a.v/100;return var_h=6*c,var_i=Math.floor(var_h),var_1=e*(1-d),var_2=e*(1-d*(var_h-var_i)),var_3=e*(1-d*(1-(var_h-var_i))),0==var_i?(var_r=e,var_g=var_3,var_b=var_1):1==var_i?(var_r=var_2,var_g=e,var_b=var_1):2==var_i?(var_r=var_1,var_g=e,var_b=var_3):3==var_i?(var_r=var_1,var_g=var_2,var_b=e):4==var_i?(var_r=var_3,var_g=var_1,var_b=e):(var_r=e,var_g=var_1,var_b=var_2),b.r=255*var_r,b.g=255*var_g,b.b=255*var_b,b.r=Math.round(b.r),b.g=Math.round(b.g),b.b=Math.round(b.b),b},toRGB:function(a){return a instanceof RGB?a:a instanceof HSV?this._HSVtoRGB(a):void 0},toHSV:function(a){return a instanceof HSV?a:a instanceof RGB?this._RGBtoHSV(a):void 0},toStr:function(a){return a instanceof HSV?"hsv("+a.h+","+a.s+","+a.v+")":a instanceof RGB?"rgb("+a.r+","+a.g+","+a.b+")":void 0}};
|