Published
Edited
Jul 1, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
illo = {
var yellow = "#ED0";
var gold = "#EA0";
var orange = "#E62";
var garnet = "#C25";
const TAU = Zdog.TAU;

let isSpinning = anim;

const illo = new Zdog.Illustration({
element: DOM.canvas(width, width * (yCount / xCount)),
dragRotate: true,
zoom: zoom,
onDragStart: function () {
isSpinning = false;
}
//rotate: { x: -TAU / 8 }
});
illo.element.style.backgroundColor = "#FDB";
illo.element.style.cursor = "move";

let arc = new Zdog.Shape({
path: [
{ x: -tileScale / 2, y: -tileScale / 2 }, // start
{
arc: [
{ x: tileScale / 2, y: -tileScale / 2 }, // corner
{ x: tileScale / 2, y: tileScale / 2 } // end point
]
},
{ line: { x: -tileScale / 2, y: tileScale / 2 } }
],
closed: true,
stroke: stroke,
color: "#636"
});

let rect = new Zdog.Rect({
width: tileScale,
height: tileScale,
stroke: stroke / 2,
color: "#E62"
});

const modes = [
{ mode: 0, x: -tileScale / 2, y: tileScale / 2, theta: 0 },
{ mode: 1, x: -tileScale / 2, y: -tileScale / 2, theta: TAU / 4 },
{ mode: 2, x: tileScale / 2, y: -tileScale / 2, theta: TAU / 2 },
{ mode: 3, x: tileScale / 2, y: tileScale / 2, theta: (3 * TAU) / 4 }
];

d3.range(yCount).map((y) =>
d3.range(xCount).map((x) => {
const mode = modes[Math.floor(Math.random() * modes.length)];
// rect.copy({
// addTo: illo,
// translate: {
// x: x * tileScale - (xCount * tileScale) / 2,
// y: y * tileScale - (yCount * tileScale) / 2
// }
// });
if (Math.random() < filledPercentage) {
arc.copy({
addTo: illo,
translate: {
x: x * tileScale - (xCount * tileScale) / 2,
y: y * tileScale - (yCount * tileScale) / 2,
z: (Math.random() - 0.5) * zMove
},
rotate: { z: mode.theta },
scale: scale
});
}
})
);

let rotX = 0;

function animate() {
rotX += 0.00001;
// rotate
if (isSpinning) {
illo.rotate.y += 0.01;
illo.rotate.x += Math.sin(rotX);
}

illo.updateRenderGraph();
requestAnimationFrame(animate);
}

// start animation
animate();

while (true) {
illo.updateRenderGraph();
yield illo.element;
}
}
Insert cell
Zdog = require("zdog@1.0.1/dist/zdog.dist.min.js")
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