Código HTML:
<html lang="en"> <head> <title>Canvas Regn</title> <script type="text/javascript"> var ctx; var imgBg; var imgDrops; var x= 0; var y= 20; function setup() { var canvas = document.getElementById('canvasRegn'); if (canvas.getContext) { ctx = canvas.getContext('2d'); setInterval('draw();', 36); imgBg = new Image(); imgBg.src = 'dimma.jpg'; imgDrops = new Image(); imgDrops.src = 'drop.png'; } } function draw() { drawBackground(); <!--regndroppe--><!--gota de lluvia--> ctx.drawImage (imgDrops, x, y); y += 0.5; if(y > 400) { y=-50; x = Math.random() * 300; } } function drawBackground(){ <!-- bakgrund --> ctx.drawImage(imgBg, 0, 0); } </script> </head> <body onload="setup();"> <canvas id="canvasRegn" width="600" height="450"style="margin:100px;"></canvas> </body> </html>