Edit in JSFiddle

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

var canvas = document.getElementById('canvas');
if (canvas.getContext) {

    ctx = canvas.getContext("2d");

    var vertices = [];
    var i;
    for (i = 0; i < 7; i++) {
        var dir = Math.random() * Math.PI * 2;
        vertices.push({
            "x": Math.random() * canvas.width,
            "y": Math.random() * canvas.height,
            "dirx": Math.sin(dir),
            "diry": Math.cos(dir)
        });
    }

    var draw = function () {
        for(i=0 ; i<vertices.length;i++){
            vertices[i].x = vertices[i].x + vertices[i].dirx * 4;
            vertices[i].y = vertices[i].y + vertices[i].diry * 4;
            if(vertices[i].x < 0 || vertices[i].x > canvas.width){
                vertices[i].dirx = - vertices[i].dirx;
            }
            if(vertices[i].y < 0 || vertices[i].y > canvas.height){
                vertices[i].diry = - vertices[i].diry;
            }
        }

        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        ctx.strokeStyle = "#FFFFFF";
        ctx.beginPath();
        ctx.moveTo(vertices[0].x, vertices[0].y)
        for (i = 1; i < vertices.length; i++) {
            ctx.lineTo(vertices[i].x, vertices[i].y);
        }
        ctx.closePath();
        ctx.stroke();

        requestAnimationFrame(draw);
    };
    requestAnimationFrame(draw);
}
<body>
    <canvas id="canvas" width="400" height="300"></canvas>
</body>
#canvas {
    background-color:black
}