Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE html>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
</body>
<script>
/*
The shadow and shadow blur effects should be the same regardless if they were
defined with filters or properties. The blur parameter is set as double when
using the shadowBlur property since its uses havlf of the value set as the
while the filter parameter is used directly as the standard deviation
fuzziness is defined with a maxDifference of 13 as to be the 5% of 256, since
the CSS spec defines the expected behavior in relation to an ideal Gaussian blur
*/
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.shadowOffsetX = 10;
ctx.shadowOffsetY = 10;
ctx.shadowBlur = 4;
ctx.shadowColor = 'red';
ctx.fillRect(20, 20, 50, 50);
ctx.shadowBlur = 8;
ctx.shadowColor = 'blue';
ctx.fillRect(100, 20, 50, 50);
ctx.shadowBlur = 20;
ctx.shadowColor = 'yellow';
ctx.fillRect(20, 100, 50, 50);
ctx.shadowBlur = 30;
ctx.shadowColor = 'cyan';
ctx.fillRect(100, 100, 50, 50);
</script>