My exmaple in JavaScript and <canvas>
. https://codepen.io/KonradLinkowski/pen/QWbjaPr
const canvas = document.querySelector('#box')
const ctx = canvas.getContext('2d')
const interpolate = (value, start, end) => (end - start) * value + start
const interpolateRGB = (value, start, end) => {
return {
r: interpolate(value, start.r, end.r),
g: interpolate(value, start.g, end.g),
b: interpolate(value, start.b, end.b)
}
}
const calcColor = (point, topLeft, topRight, bottomLeft, bottomRight) => {
const top = interpolateRGB(point.x, topLeft, topRight)
const bottom = interpolateRGB(point.x, bottomLeft, bottomRight)
const result = interpolateRGB(point.y, …
Run Code Online (Sandbox Code Playgroud)css linear-gradients background-color css-gradients bilinear-interpolation