diff options
Diffstat (limited to 'interpolate.js')
-rw-r--r-- | interpolate.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/interpolate.js b/interpolate.js new file mode 100644 index 0000000..e6166fa --- /dev/null +++ b/interpolate.js @@ -0,0 +1,24 @@ +function interpolateStyle(el, prop, cb, reset = true) { + if (reset) { + el.style.setProperty(prop, ''); + } + const intact = getComputedStyle(el); + const start = intact.getPropertyValue(prop); + el.style.setProperty(prop, cb(start)); +} + +function itpColor(prog, target) { + return start => { + const [ sr, sg, sb ] = start.match(/[0-9]{1,}/g).map(n => parseInt(n)); + const [ tr, tg, tb ] = target.match(/[0-9]{1,}/g).map(n => parseInt(n)); + const [ sh, ss, sl ] = rgbToHsl(sr, sg, sb); + const [ th, ts, tl ] = rgbToHsl(tr, tg, tb); + const [ ih, is, il ] = [ + sh + prog * (th - sh), + ss + prog * (ts - ss), + sl + prog * (tl - sl) + ]; + const [ ir, ig, ib ] = hslToRgb(ih, is, il).map(n => parseInt(n)); + return `rgb(${ir}, ${ig}, ${ib})`; + }; +} |