<svg id="svg" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="1" fill="white" stroke="black"></circle>
</svg>
#svg {
width: 100%;
height: 100%;
background: #eee;
}
body {
margin: 0;
height: 100vh;
}
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);
}
}
View Compiled
const getRandomInt = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
};
const NUM_LINES = 69;
const svg = document.querySelector("#svg");
const doArt = () => {
// Clear old
let oldLines = svg.querySelectorAll("line");
if (oldLines) oldLines.forEach((line) => line.remove());
// Draw new
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);
};
doArt();
window.addEventListener("click", doArt);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.