Drawing the burst with SVG lines

The piece relies on SVG's <line x1 y1 x2 y2> element, which suits a radiate-from-center effect with very little math. The origin point x1/y1 never changes, while x2/y2 get random values on each draw. Because the root uses viewBox="0 0 100 100", placing lines is straightforward by eye. An alternative is -50 -50 100 100, which puts the coordinate 0 0 at the center.

Randomization as a building block

const getRandomInt = (min, max) => {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

A helper like this is handy for generative work. Here it drives line positions plus the stroke width and opacity of the gray tones, not just geometry. After using it repeatedly, the author argues native JavaScript ought to ship with a math helper this legible.

Building markup from template literals

Assembling the SVG nodes through template literals keeps the generation code readable:

let newLines;
for (let i = 0; i < NUM_LINES; i++) {
  newLines += `
  <line 
    x1="50"
    y1="50"
    x2="${getRandomInt(10, 90)}"
    y2="${getRandomInt(10, 90)}"
    stroke="rgba(0, 0, 0, 0.${getRandomInt(0, 25)})"
    stroke-linecap="round"
    stroke-width="${getRandomInt(1, 2)}"
  />`;
}

svg.insertAdjacentHTML("afterbegin", newLines);

Regenerating on click

Since a single function starts the whole drawing process, wiring up click-to-regenerate takes almost nothing:

doArt();

window.addEventListener("click", doArt);

Stroke ends and animation

Uppercase-nothing aesthetics: setting stroke-linecap="round" makes the result noticeably nicer, a flourish SVG stroke endings support directly.

The lines themselves never change position. The apparent motion is a CSS transform applied to the lines:

line {
  transform-origin: center;
  animation: do 4s infinite alternate;
}
line:nth-child(6n) {
  animation-delay: -1s;
}
line:nth-child(6n + 1) {
  animation-delay: -2s;
}
line:nth-child(6n + 2) {
  animation-delay: -3s;
}
line:nth-child(6n + 3) {
  animation-delay: -4s;
}
line:nth-child(6n + 4) {
  animation-delay: -5s;
}

@keyframes do {
  100% {
    transform: scale(0.69);
  }
}

It reads as though each line grows and shrinks in length, but the entire line is being scaled via scale(). The thinning that scaling causes barely registers because each line is far longer than it is wide. The negative animation delays are deliberate: they stagger the individual animations so the ensemble feels somewhat random while everything still starts together.

Possible next steps

  • Add color. Well-chosen palettes could work nicely.
  • Group the randomization. Strokes evenly randomized between 1 and 10 read as almost too random, whereas ranges like 1–2, 2–4 or 8–10 produce a more considered aesthetic. The same logic applies to colorization, where fully random hues are too chaotic and tighter constrained randomization is more interesting.
  • Introduce more motion: rotation, travel across the page, additional bursts.
  • Above all, expose more parameters on the demo itself. dat.GUI is a well-worn option for that kind of live control panel.