UNPKG

@threlte/extras

Version:

Utilities, abstractions and plugins for your Threlte apps

23 lines (22 loc) 637 B
import { Color } from 'three'; /** * applies `gradient` to `context` */ export const applyGradient = (context, gradient) => { context.save(); let lastFillStyle = context.fillStyle; context.fillStyle = gradient; context.fillRect(0, 0, context.canvas.width, context.canvas.height); context.fillStyle = lastFillStyle; context.restore(); }; const color = new Color(); /** * adds each `stop` of `stops` to the gradient */ export const addStops = (gradient, stops = []) => { for (const stop of stops) { gradient.addColorStop(stop.offset, color.set(stop.color).getStyle()); } return gradient; };