« get me outta code hell

interpolate.js - precanon - Homestuck^2: Preceeding Canon - (re)presentation of HS2 stylized upon Prequel
summary refs log tree commit diff
path: root/interpolate.js
blob: e6166fadba5bdb45d7eeb1a5207a55ef8a6f31a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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})`;
    };
}