add linear gradient
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user