Published
Edited
Mar 3, 2022
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
image = FileAttachment("squirtle.png").image()
Insert cell
polygon_points = getImageOutline(image)
Insert cell
svg = {
var w = d3.max(polygon_points, (d) => d.x);
var h = d3.max(polygon_points, (d) => d.y);
var first_point = polygon_points[0];
var last_point = polygon_points[polygon_points.length - 1];
return html`<svg viewbox="0 0 ${w} ${h}" width="300">
<path d="M ${first_point.x} ${first_point.y}
${polygon_points.map((p) => ` L ${p.x} ${p.y}`)}
L ${last_point.x} ${last_point.y}"/>
</svg>`;
}
Insert cell
Insert cell
image_to_svg(await FileAttachment("squirtle.png").image())
Insert cell
image_to_svg = (img) => {
var polygon_points = getImageOutline(img);
var w = d3.max(polygon_points, (d) => d.x);
var h = d3.max(polygon_points, (d) => d.y);
var first_point = polygon_points[0];
var last_point = polygon_points[polygon_points.length - 1];
return html`<svg viewbox="0 0 ${w} ${h}" width="300">
<path d="M ${first_point.x} ${first_point.y}
${polygon_points.map((p) => ` L ${p.x} ${p.y}`)}
L ${last_point.x} ${last_point.y}"/>
</svg>`;
}
Insert cell
Insert cell
getImageOutline = (
await import("https://cdn.skypack.dev/image-outline@0.1.0?min")
).default
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