add linear gradient

This commit is contained in:
Quentin Leonetti
2019-07-17 21:27:56 +02:00
parent 267e14eb6f
commit 7d27897d8b
3 changed files with 31 additions and 0 deletions

View File

@@ -215,6 +215,12 @@ function Library (ronin) {
return getComputedStyle(el).getPropertyValue(`--${variable}`)
}
// Gradients
this.gradient = ([x1,y1,x2,y2], colors=['white','black']) => {
return ronin.surface.linearGradient(x1, y1, x2, y2, colors)
}
// Pixels
this.pixels = (rect, fn, q) => {

View File

@@ -61,6 +61,15 @@ function Surface (ronin) {
context.closePath()
}
this.linearGradient = function(x1, y1, x2, y2, colors, context = this.context) {
const gradient = context.createLinearGradient(x1, y1, x2, y2)
const step = 1/(colors.length - 1)
colors.forEach((color,i) => {
gradient.addColorStop(i*step, color)
})
return gradient
}
// Tracers
this.trace = function (shape, context) {