Edit in JSFiddle

(function() {
  var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                              window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame;
})();

var N_STARS = 100;
var STAR_SIZE = 2;

var canvas = document.getElementById('canvas');
if (canvas.getContext) {
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = "white";

    var draw = function () {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        var i, x, y;
        for (i = 0; i < N_STARS; i++) {
            x = Math.random() * canvas.width;
            y = Math.random() * canvas.height;
            ctx.fillRect(x, y, STAR_SIZE, STAR_SIZE);
        }
        requestAnimationFrame(draw);
    };
    requestAnimationFrame(draw);
}
<body>
    <canvas id="canvas" width="400" height="300"></canvas>
</body>
#canvas {
    background-color:black
}