Public
Edited
Jan 26
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// width = 800
Insert cell
rectangles = {
const rectangles = [];
for (let x = 0; x < width; x += gap) {
for (let y = 0; y < height; y += gap) {
// skip some squares
if (Math.random() < skipPct) continue;

const side = (Math.random() * (maxSide - minSide) + minSide) * gap;
const offsetX = Math.random() * maxOffset * gap;
const offsetY = Math.random() * maxOffset * gap;
const strokeWidth = Math.random() * side + "px";

const angle = Math.random() * 350 - 50;
const duration = Math.random() * 3 + 1;

rectangles.push({ x, y, side, offsetX, offsetY, strokeWidth });
}
}

return rectangles;
}
Insert cell
rectanglesWithColor = rectangles.map(({x, y, side, offsetX, offsetY, strokeWidth}) => {
const { h, s, l } = d3.hsl(bgColor);
const randColNum = Math.floor(Math.random() * numColors) + 1;
const newH = (h + randColNum * (360 / (numColors + 1))) % 360;
const shadow = "drop-shadow(3px 3px 2px rgba(0, 0, 0, .7))";

const color = d3.hsl(newH, s + ds, l + dl); // bad attempt at complementary colors
return {x, y, side, offsetX, offsetY, strokeWidth, color, shadow};
})
Insert cell
rectanglesSVG = rectanglesWithColor.map(
({ x, y, side, offsetX, offsetY, strokeWidth, color, shadow }) => {
const angle = Math.random() * 350 - 50;
const duration = Math.random() * 3 + 1;
const rectStyle = `
-webkit-filter: ${shadow};
filter: ${shadow};
${
animate
? `--angle: ${angle}deg; animation: ${duration}s infinite alternate slide-in;`
: ""
}`;

return htl.svg`<rect
x=${x - side / 2 - offsetX} y=${y - side / 2 - offsetY}
width="${side}" height="${side}"
fill="none"
stroke="${color}"
stroke-width="${strokeWidth}"
style="${rectStyle}"
></rect>`;
}
)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more