export function easeInOut(t, amt=2) {
    let tPow = Math.pow(t, amt);
    return tPow / (tPow + Math.pow(1 - t, amt));
}

export function sinEaseInOut(t) {
	return 0.5 - 0.5 * Math.cos(Math.PI * t);
}

export function slurp(val1, val2, amt) {
    return (val2 - val1) * amt + val1;
}

export function experp(val1, val2, amt) {
    return Math.exp(
        slurp(
            Math.log(val1),
            Math.log(val2),
            amt
        )
    )
}

export function clampedSlurp(val1, val2, amt) {
    if (amt < 0) {
        return val1;
    }
    if (amt > 1) {
        return val2;
    }
    return slurp(val1, val2, amt);
}

export function clamp(amt, val1, val2) {
    if (amt < 0) {
        return val1;
    }
    if (amt > 1) {
        return val2;
    }
    return amt;
}

/**
 * Extracts a 0-1 interval from a section of a 0-1 interval
 *
 * For example, if min == 0.3 and max == 0.7, you get:
 *
 *           0.3  0.7
 *     t: 0 --+----+-- 1
 *           /      \
 *          /        \
 *         /          \
 *     -> 0 ---------- 1
 *
 * Useful for making sub animations.
 *
 * Doesn't do any clamping, so you might want to clamp yourself.
 */
export function divideInterval(t, min, max) {
    return (t - min) / (max - min);
}

export function rgb(r, g, b) {
	return 'rgb('+r+','+g+','+b+')';
}

export function gray(whiteAmt) {
    whiteAmt = clamp(whiteAmt, 0, 1);
	const whiteRgb = Math.floor(255 * whiteAmt);
	return rgb(whiteRgb, whiteRgb, whiteRgb);
}

export function hsl(h, s, l) {
    h = Math.floor(360 * h);
    s = Math.floor(100 * s) + '%';
    l = Math.floor(100 * l) + '%';
    return 'hsl('+h+','+s+','+l+')';
}