Created
August 20, 2017 06:39
-
-
Save doxas/677692888798c9bf3c90eb9e9e397cbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DrawCanvas { | |
constructor(size){ | |
this.canvas = document.createElement('canvas'); | |
this.canvas.width = this.canvas.height = size; | |
this.ctx = this.canvas.getContext('2d'); | |
} | |
drawGradationShadow(colorRGB){ | |
let center = [this.canvas.width / 2, this.canvas.height / 2]; | |
let radius = Math.min(center[0], center[1]) * 0.9; | |
let colorFill = 'rgba(' + colorRGB.join(',') + ', 0.0)'; | |
let colorShadow = 'rgba(' + colorRGB.join(',') + ', 1.0)'; | |
let gradient = this.ctx.createRadialGradient( | |
center[0], center[1], radius, | |
center[0], center[1], 0, | |
); | |
gradient.addColorStop(0, colorFill); | |
gradient.addColorStop(1, colorShadow); | |
this.ctx.fillStyle = gradient; | |
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height); | |
} | |
getElement(){ | |
return this.canvas; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment