Created
June 15, 2018 04:26
-
-
Save mauriciomassaia/38a1e177fe41ee28ea7ae7971028cd9f to your computer and use it in GitHub Desktop.
Canvas 2d Mask
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
const size = 512 | |
const size2 = size / 2 | |
const c = document.createElement('canvas') | |
c.width = size | |
c.height = size | |
document.body.appendChild(c) | |
const ctx = c.getContext('2d') | |
ctx.fillStyle = '#ff0000' | |
ctx.fillRect(0, 0, size, size) | |
// applying the circle mask | |
ctx.globalCompositeOperation = 'destination-in' | |
ctx.fillStyle = '#000000' | |
ctx.arc(size2, size2, size2, 0, 2*Math.PI) | |
ctx.fill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment