var ctx = document.querySelector("canvas").getContext("2d"),
inp = document.querySelector("input"),
w = ctx.canvas.width,
h = ctx.canvas.height,
balls = [];
ctx.fillStyle = "rgb(0, 154, 253)";
generate(inp.value)
inp.onkeyup = function() {generate(this.value)};
function generate(txt) {
var i, radius = 5,
data32;
balls = [];
ctx.clearRect(0, 0, w, h);
ctx.fillText(txt.toUpperCase(), 0, 10);
data32 = new Uint32Array(ctx.getImageData(0, 0, w, h).data.buffer);
for(i = 0; i < data32.length; i++) {
if (data32[i] & 0xff000000) {
balls.push({
x: (i % w) * radius * 2 + radius,
y: ((i / w)|0) * radius * 2 + radius,
radius: radius,
a: (Math.random() * 250)|0
});
}
}
}
(function animate() {
ctx.clearRect(0, 0, w, h);
ctx.beginPath();
for(var i = 0, ball; ball = balls[i]; i++) {
var dx = Math.sin(ball.a * 0.2) + ball.radius,
dy = Math.cos(ball.a++ * 0.2) + ball.radius;
ctx.moveTo(ball.x + ball.radius + dx, ball.y + dy);
ctx.arc(ball.x + dx, ball.y + dy, ball.radius, 0, 6.28);
ctx.closePath();
}
ctx.fill();
requestAnimationFrame(animate);
})();
body {font:bold 16px sans-serif}
<label>Type some text: <input value="PIXELS"></label><br>
<canvas width=1024></canvas>