WebSVG / voronoi

Parametric Voronoi generator with real time editing and SVG export
https://voronoi-editor.web.app
179 stars 27 forks source link
bootstrap client-side css-grid geometric-algorithms sampling-methods static-site svg svg-filters template-string vanilla-js voronoi

Overview

Parametric Voronoi generator with real time editing and SVG export

Live demo

Chrome is tested as web browser, Edge might work but Firefox might show white page only

Discussions

get support, give feedback or simply chat to brainstorm about new ideas

https://github.com/WebSVG/voronoi/discussions

3D Printed Voronoi Shapes

Photos and 3D Models available

https://www.homesmartmesh.com/3dprinting/voronoi-shapes/

User Guide

Overview

We see above the user generating new sets of seeds with their resulting voronoi diagram, hiding and viewing seeds, cells and edges, changing the number of seeds with a slider while the view updates in real time, editing the cells by moving them, removing and adding cells, changing the cells shape to quadratic bezier, simple edges and back to cubic bezier, finally adjusting the space between cells before exporting in an SVG file.

Export seeds coordinates

The seeds coordinates are what allows to generate again the same voronoig diagram

cells retraction

cubic bezier minimum edge size

Shaped tesselation area

step 1 : sampling

the shape is approximated with a set of linear interpolation points along the path

step 2 : cells isolation

the naive (and not so nice) way

    <defs>
        <clipPath id="cut-off-cells">
            <path xmlns="http://www.w3.org/2000/svg" d=${path} fill="#991155" fill-opacity="0.9"></path>
        </clipPath>
    </defs>

this applies an svg mask, with the SVG clipPath function, it would result in this

the nicer way

Note : the higher the number of samples per seed, the more the cells will allign the shape's path

Before explaining how this works, let's inspect that the voronoi cells are natually alligned along the custom path we provided as input

Below is the revealed secret. There are seeds actually being sampled outside the path area for the sole purpose of giving support to the inside cells not to expand till the external frame. Also important that the cells are not just simply randomly sampled inside and outside the area, they are rather avoiding the path with a distance cost factor, that prevents cells from cutting the edges to a certain extent.

Seeds sampling cost map

In all sampling variants, the seeds do have the neighbors distance as cost minimzation factor. Using a shape's path, the cost add up to avoid the path with a distance. Here, a png image gray scale is used as a cost map that is weighted with the neighbors distance.

In the animation below, after dropping a spiral cost map, the Map Cost Vs Dist slider is moved from 5 to 20 to concentrate the cells in the darker areas.

SVG Path Shaped area and png seeds cost map

Filters : Displacement with Turbulence

warning ! The svg filters effect, though part of the standard and viewable in browsers are not always supported by CAD programs such as Fusion360 !

Features details

Planned features

discarded features

License

MIT

Issues

https://github.com/WebSVG/voronoi/issues

Dependencies

node dependencies are not required to serve the project locally, but only to reference the used dependencies

Vornoi js Library

Vector module from matter.js

bootstrap

Export / Download

  npm install file-saver --save
  file-saver@2.0.2

References