jc-color
Version:
A JavaScript tool for color compute and console print tool both for NodeJS and Browser.
1 lines • 1.72 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.creatGeadient=exports.creatGeadientBase=void 0;const converters_1=require("../converters"),jc_utils_1=require("@jcstdio/jc-utils");function perStepNumbers(e,r,t=!1){if(r<e){if(t)throw(0,jc_utils_1.ValueError)("Gradient color number numst great than input color numbers");return[]}if(e===r)return[0];var n=r-e,i=e-1;if(0==n%i){var o=[];for(let e=0;e<i;e++)o.push(parseInt((n/i).toString()));return o}var s=n%i,a=[];for(let e=0;e<i;e++)a.push(parseInt((n/i).toString()));for(let e=0;e<s;e++)a[e]++;return a}function creatGeadientBase(e,r,t,n=!0,i=!0){var o=e.red,s=e.green,e=e.blue,a=r.red,u=r.green,r=r.blue,l=(0,jc_utils_1.arithmeticProgression)(o,a,t,n,i),c=(0,jc_utils_1.arithmeticProgression)(s,u,t,n,i),_=(0,jc_utils_1.arithmeticProgression)(e,r,t,n,i),d=[];for(let e=0;e<l.length;e++)d.push({red:l[e],green:c[e],blue:_[e]});return d}function creatGeadient(e,r,t=!1){var n=e.length;if(n<2)throw(0,jc_utils_1.ValueError)("Gradient color requires at least two values.");var i=(0,converters_1.colorsToChannels)(...e),e=i.length;if(r<e){if(t)throw(0,jc_utils_1.ValueError)("The number of gradient colors cannot be less than the original color number.");return i}if(e===r)return i;var t=i[0],o=[{red:t.red,green:t.green,blue:t.blue}],s=perStepNumbers(n,r);for(let e=0;e<n-1;e++){var a=i[e],u=i[e+1],l=s[e],c=(0,jc_utils_1.arithmeticProgression)(a.red,u.red,l,!1,!0),_=(0,jc_utils_1.arithmeticProgression)(a.green,u.green,l,!1,!0),d=(0,jc_utils_1.arithmeticProgression)(a.blue,u.blue,l,!1,!0);for(let e=0;e<c.length;e++)o.push({red:c[e],green:_[e],blue:d[e]})}return o}exports.creatGeadientBase=creatGeadientBase,exports.creatGeadient=creatGeadient;