Last active
December 31, 2019 21:44
-
-
Save worldoptimizer/427244f6cd6126ce2396fdde2e3cb697 to your computer and use it in GitHub Desktop.
This file contains 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
// Lower value increases trail duration. | |
const CANVAS_CLEANUP_ALPHA = 0.3; | |
// Cleans up the canvas by removing older trails. | |
// ... | |
function cleanCanvas() { | |
// Set 'destination-out' composite mode, so additional fill doesn't remove non-overlapping content. | |
context.globalCompositeOperation = 'destination-out'; | |
// Set alpha level of content to remove. | |
// Lower value means trails remain on screen longer. | |
context.fillStyle = `rgba(0, 0, 0, ${CANVAS_CLEANUP_ALPHA})`; | |
// Fill entire canvas. | |
context.fillRect(0, 0, canvas.width, canvas.height); | |
// Reset composite mode to 'lighter', so overlapping particles brighten each other. | |
context.globalCompositeOperation = 'lighter'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment