react-audio-visualizers
Version:
<h1 align="center">React Audio Visualizers</h1>
24 lines (23 loc) • 894 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorUtils = void 0;
var three_1 = require("three");
var ColorUtils = /** @class */ (function () {
function ColorUtils() {
}
ColorUtils.getColorGradientTexture = function (colors) {
var length = colors.length;
var canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 32;
var context = canvas.getContext('2d');
var gradient = context.createLinearGradient(0, 0, 0, 32);
// TODO: handle number colors
colors.forEach(function (color, i) { return gradient.addColorStop(length === 1 ? 1 : i / (length - 1), color); });
context.fillStyle = gradient;
context.fillRect(0, 0, 1, 32);
return new three_1.CanvasTexture(canvas);
};
return ColorUtils;
}());
exports.ColorUtils = ColorUtils;