Coder Social home page Coder Social logo

websvg / voronoi Goto Github PK

View Code? Open in Web Editor NEW
170.0 6.0 26.0 15.38 MB

Parametric Voronoi generator with real time editing and SVG export

Home Page: https://voronoi-editor.web.app

HTML 1.85% JavaScript 98.15%
bootstrap client-side css-grid geometric-algorithms sampling-methods static-site svg vanilla-js voronoi svg-filters template-string

voronoi's Introduction

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

  • Generate Diagram
  • Edit cells
  • Export SVG

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

  • seeds can be exported as a json text file containing each seed coordinate
  • the seeds.json can be imported by drag and drop on the view area
  • it is possible therefore to share seeds structures and continue working on a seeds set at any point in time

cells retraction

  • The cells are not scaled down, their edges are rather retracted in parallel to their original location.
  • When retracting cells as a consequence some edges could become irrelevant and the shape might decrese in edges number.

  • Below is another example where we see in debug mode the translated edges and the discarded one is red

cubic bezier minimum edge size

  • goal is to filter small edge to avoid sharp bezier curves
  • the quadratic bezier only has one control point, so using the center of the removed edge would still break the tangency alignment with the previous curve
  • clean way would require ignoring the corresponding site completely and extend the left edges till the small edge is nullified, thus reducing the total number of sides of the cell
  • therfore, in order to keep shapes tangent to the sides, min edge ignore is only implemented in quadratic bezier.

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

  • First issue, Fusion360 as example does not support clipPath
  • Second issue, the cut is very sharp and breaks the bezier shape of the cells

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

  • drag and drop a png file on the editor's window
  • run sampling with preferrably a high sample count (~100 or more)

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

  • Generate Voronoi Diagram

  • Export to SVG file

  • Shaped Tesselation area with an SVG path

  • Cost map for Seeds sampling from a png file

    seeds

  • Edit seeds : add, move, remove

  • Export and import seeds (drag and drop seeds.json) and continue editing of an existing seeds set

    • seeds contain window size info since 26.04.2020, prio formats with seeds array only have to have window size adjust manually before import
  • Parametric Seeds generation

    • Controlled seeds spread regularity with multiple sampling and keeping best candidate (farthest from neighbors)
    • Optionally include distance from walls to the sampling selection cost
  • Range slider with interactive update for adding and removing seeds to and out of existing set

  • rearrange seeds when modifying window size

  • Shaped tesselation area

    • sampling points inside an SVG path with document.elementFromPoint(x, y);
  • Concentration cost map for seeds sampling

    cells

  • different cells types

    • bezier quadratic
    • bezier cubic
    • simple geometric edges
  • cells edges retraction. Not cells scale but edges parallel rertraction with handling of closed edges discard

  • Shaped tesselation area

    • display of cells which seeds are within an SVG path
    • the option is available to simply cut cells with an SVG mask

    gui

  • grid based, responsive svg and menu areas

  • Show/hide (cells, edges, seeds) and independently configure the SVG export

  • Browser local storage of config parameters (No storage of SVG nor seeds as they can be saved separately)

  • SVG filters for displacement and turbulence, but note that they can only be seen on the browser and they're not supported by tools such as Fusion360

  • display of width and height with unit ratio

    • transform scale possible but Fusion360 ignores the scale transform

    cost map

  • display / hide cost map

  • slider to weight cost map vs distance

Planned features

  • edges cells filet effect
  • add irregularities to the edges thickness (randomize retraction)
  • improve error alerts by using boostrap auto vanishing alerts
  • random colors for cells

discarded features

  • export scale with a ratio (adjusting to a given unit)

    • feature brings an ambiguous usage as svg is supposed to be scalable and should not require a fixed scale
    • extremely difficult, due to dependency to shape input that is svg and which size has to match, could be exported
    • cost map is png with pixel units, so would also deviate from map view
    • simple svg scale function not recognised by Fusion360
    • modifying seeds coordinates to deviate them far away from pixels values might result in floating precision errors, resulting in unhandled voronoi cases
    • could have been possible to copy all of the cells, edges structures and scale them one by one before export
    • as a workaround, provided view with ratio unit
  • detract quadratic bezier short edges

    • cells retraction "Space between cells" is providing a good enough short edges removal, combined with space though. It is hard to differentiate the effect of both, and it would break the Voronoi equalities
  • edit seed weight to modify cells size (? requires a new engine, or use cells retraction technique) (editing singe seed weight,cartographic seeds weight)

    • Would break the voronoi intuitive equality, and requires a new engine. Also wuold require the user to tweak each cell separately. The cost map is a good solution how to achieve the last point (cartographic seeds weight), as the cells size is a one to one match to the seeds dispertion.

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

  • 'gorhill' Javascript Voronoi library
    • github repo
    • live demo
    • used rhill-voronoi-core.js from commit 3fe2165
    • modified for ES2015 module import

Vector module from matter.js

  • modified ./node_modules/matter-js/src/geometry/Vector.js for ES2015 module import

bootstrap

Export / Download

  • Filesaver
  npm install file-saver --save
  [email protected]

References

voronoi's People

Contributors

dependabot[bot] avatar neuroradiology avatar thenickdude avatar wassfila avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

voronoi's Issues

SVG path shaped area import error

Discussed in #30

Originally posted by Josseflos February 7, 2023
Hi there,

I am trying to import a SVG file in the Voronoi web editor (Chrome), but keep receiving the same error: "only supported import of SVG with a single path on the top level". I am using Inkscape to create a SVG and am making sure that the file is a single path on the top layer, but even when plucking simples shapes from the internet, the error comes up. Does anyone know what could go wrong, or could anyone share a file that works, so I can compare it with other files?

Thanks in advance!

Jos

feature requests: mouseover preview for the 'add' function, undo/redo

Discussed in #21

Originally posted by raminrahni June 14, 2022
Thank you so much for creating and sharing this wonderful tool! It's incredibly useful. Are there any plans to implement a preview feature for the 'add' function? It would be super helpful to know where the cell is going to be cut before clicking, especially in the absence of an undo function (another feature that would be extremely useful). Thanks!

Add offset from shape edges

My goal is to get any shape with holes and generate a Voronoi diagram inside it. With the app I generated a mesh then modified it in Illustrator to get this result:

image

Then I imported the DXF to Fusion:

image

It would be nice to add such features that generate such DXF

Add text inside each cell

Hi, this feature would be extremely useful for labeling cells and would love to see this added. Thank you so much for the time and consideration.

Failing cubic bezier import on Fusion360

Wondering if this is not a Fusion360 limitation...

Fusion360

image

Browser

image

<svg id="main_svg" 
    xmlns="http://www.w3.org/2000/svg" width="100%" height="60%">
    <g id="svg_g_bezier_cells">
        <path d="M412.4717425873301,20.098834050356288 C412.9389244865767,34.99766810071258 412.9389244865767,34.99766810071258 454.384561218125,86.329207020215 S495.83019794967333,137.6607459397174 541.3150989748367,145.89898089893188 S586.8,154.1372158581464 586.8,79.66860792907319 S586.8,5.200000000000001 499.40228034404174,5.2 S412.0045606880835,5.199999999999999 412.4717425873301,20.098834050356288 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M254.64669827148415,48.918126343501164 C256.57708726719244,92.63625268700233 256.57708726719244,92.63625268700233 290.47610686741575,109.89177322231262 S324.37512646763906,127.1472937576229 345.439150408597,118.93807123126899 S366.5031743495549,110.7288487049151 384.5310317951909,73.26311304884592 S402.55888924082694,35.79737739277677 402.07916912199056,20.498688696388385 S401.5994490031542,5.200000000000003 327.157879139465,5.200000000000003 S252.71630927577587,5.200000000000004 254.64669827148415,48.918126343501164 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M111.47651245541348,63.24613880922354 C143.09211635964837,121.29227761844707 143.09211635964837,121.29227761844707 177.55284095613632,133.65254733040913 S212.0135655526243,146.0128170423712 229.1298918699356,120.22209769848071 S246.24621818724688,94.43137835459021 244.27619699404454,49.815689177295106 S242.30617580084223,5.2 161.0835421760104,5.2 S79.86090855117858,5.2 111.47651245541348,63.24613880922354 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M394.0328773500384,160.54030700345356 C412.0911652827125,206.04997694269602 412.0911652827125,206.04997694269602 448.94951470777835,173.9264550404453 S485.8078641328442,141.80293313819456 447.3620932580078,94.18680899141006 S408.91632238317135,46.57068484462556 392.4454559002678,80.80066095441833 S375.9745894173643,115.03063706421112 394.0328773500384,160.54030700345356 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M41.57271262443263,257.5219007092888 C77.94542524886526,246.75134230934793 77.94542524886526,246.75134230934793 105.80174863020277,186.23283549666826 S133.65807201154027,125.71432868398861 100.83820355327575,65.4571643419943 S68.01833509501122,5.2 36.60916754750561,5.2 S5.2,5.2 5.200000000000001,136.7462295546148 S5.200000000000001,268.29245910922964 41.57271262443263,257.5219007092888 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M226.5756952201271,177.68458375826035 C233.4104792160052,202.1921736235795 233.4104792160052,202.1921736235795 266.29262347010354,193.41891620639382 S299.1747677242019,184.64565878920817 308.3854268745969,160.00603901122201 S317.5960860249919,135.36641923323583 285.44122383481886,118.99872213237484 S253.28636164464575,102.63102503151384 236.5136364344474,127.90400946222752 S219.74091122424903,153.1769938929412 226.5756952201271,177.68458375826035 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M340.61541029074374,211.04945707789375 C371.90223306339686,234.91439573813838 371.90223306339686,234.91439573813838 387.9643884610646,224.41892984397276 S404.0265438587323,213.92346394980711 385.69992266630635,167.73755282255388 S367.3733014738804,121.55164169530067 347.7609836135532,129.1950949131804 S328.14866575322606,136.83854813106012 318.73862663565836,162.01153327435463 S309.32858751809067,187.18451841764914 340.61541029074374,211.04945707789375 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M136.83213670271294,252.95263505751757 C184.3003602024225,259.0879861059363 184.3003602024225,259.0879861059363 187.16725267246562,258.03711958314034 S190.03414514250872,256.9862530603443 203.59189829212087,243.00112384540694 S217.14965144173303,229.01599463046955 220.7431231929268,218.69314435184276 S224.33659494412055,208.37029407321597 217.07161341658048,182.3201383165091 S209.80663188904043,156.2699825598022 176.0050197927462,144.14612134964364 S142.20340769645196,132.02226013948507 115.78366044972768,189.41977207429193 S89.36391320300339,246.8172840090988 136.83213670271294,252.95263505751757 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M456.3650071988532,244.2336517479963 C495.6668486504737,272.9551035312676 495.6668486504737,272.9551035312676 541.2334243252369,263.62353874139376 S586.8000000000001,254.2919739515199 586.8000000000001,209.49919844083422 S586.8000000000001,164.70642293014856 540.6660937394013,156.35064000449304 S494.5321874788026,147.99485707883753 455.79767661301764,181.75352852178128 S417.06316574723274,215.512199964725 456.3650071988532,244.2336517479963 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M286.11406470588327,258.5438028909689 C344.1381010501169,287.8655184843177 344.1381010501169,287.8655184843177 354.66132912089193,265.36799256152307 S365.18455719166695,242.87046663872843 333.5830866020033,218.76552115813325 S301.98161601233966,194.66057567753805 267.8845107506048,203.75799582539813 S233.78740548887,212.8554159732582 230.93871692525983,221.03875163543916 S228.09002836164962,229.22208729762008 286.11406470588327,258.5438028909689 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M404.95002351686037,310.25537024748405 C456.4901732048671,327.9211067664456 456.4901732048671,327.9211067664456 471.96121122142625,303.8697827173236 S487.4322492379854,279.8184586682016 448.4314920003692,251.3170366701981 S409.43073476275293,222.81561467219458 392.592151576106,233.81842040816616 S375.7535683894591,244.8212261441377 364.5817211091563,268.7054299363301 S353.40987382885356,292.58963372852253 404.95002351686037,310.25537024748405 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M241.94500111432262,309.3554819214078 C283.87553034939856,357.07820962599567 283.87553034939856,357.07820962599567 307.677748885824,338.65303445071754 S331.4799674222494,320.22785927543947 335.89245523457595,308.90441163795265 S340.3049430469025,297.5809640004659 281.5289314936981,267.87924721106316 S222.75291994049377,238.17753042166044 211.38369590987026,249.90514231924016 S200.0144718792467,261.6327542168199 241.94500111432262,309.3554819214078 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M84.97435208729028,381.939134605617 C164.74870417458058,402.4882142696192 164.74870417458058,402.4882142696192 171.9636795856809,335.7003612329611 S179.17865499678123,268.91250819630295 130.6423419607188,262.63910470409087 S82.10602892465639,256.36570121187873 43.653014462328194,267.7522711990199 S5.200000000000001,279.1388411861611 5.200000000000001,320.2644480638879 S5.200000000000002,361.39005494161484 84.97435208729028,381.939134605617 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M226.2141068376347,382.52935017653226 C276.9604018687963,364.9642959688427 276.9604018687963,364.9642959688427 234.17272594486266,316.26601706608335 S191.38505002092904,267.56773816332407 190.55174616398358,267.8731877522888 S189.71844230703815,268.1786373412535 182.59312705675563,334.1365208627377 S175.46781180647312,400.0944043842219 226.2141068376347,382.52935017653226 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M378.58072875901746,365.47476044191444 C415.38361017159,408.5048618561272 415.38361017159,408.5048618561272 433.94550000389233,385.31373818866314 S452.5073898361947,362.122614521199 452.919418210887,349.9774967816637 S453.3314465855793,337.8323790421284 401.4817967347749,320.0605592393259 S349.63214688397045,302.28873943652343 345.7049971152077,312.3666992321125 S341.77784734644484,322.4446590277016 378.58072875901746,365.47476044191444 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M524.8827595536965,385.9778384442209 C586.8,411.37014313998395 586.8,411.37014313998395 586.8,338.1389795687876 S586.8,264.90781599759123 542.2224221645462,274.03684422907986 S497.64484432909245,283.16587246056855 480.726126414575,309.46776420320475 S463.8074085000575,335.769655945841 463.3864638037252,348.1775948471494 S462.96551910739294,360.58553374845786 524.8827595536965,385.9778384442209 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M300.68755135125684,407.47826810829775 C314.4374408639735,445.9737569942959 314.4374408639735,445.9737569942959 361.4449132384975,437.56374968414343 S408.45238561302153,429.15374237399095 409.2422625318438,423.7011167081117 S410.032139450666,418.24849104223244 372.5506341451834,374.424939392244 S335.0691288397008,330.6013877422556 311.30383080414447,348.99798294735035 S287.53853276858814,367.39457815244504 287.23809730356413,368.1886786873723 S286.9376618385401,368.9827792222996 300.68755135125684,407.47826810829775 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M502.85563277844517,456.95823924389754 C586.8000000000004,484.4198220521019 586.8000000000004,484.4198220521019 586.8000000000004,453.5152723972959 S586.8000000000004,422.61072274248994 523.0368302252859,396.4614011057909 S459.2736604505714,370.3120794690919 439.86681974558866,394.5588801370282 S420.4599790406059,418.80568080496454 419.68562229874794,424.1511686203288 S418.91126555688993,429.4966564356931 502.85563277844517,456.95823924389754 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M192.58288863004236,499.1505327026981 C210.85726241531265,586.7999999999993 210.85726241531265,586.7999999999993 221.70745964953448,586.7999999999993 S232.55765688375632,586.7999999999992 268.9520672476226,519.1201340139364 S305.3464776114889,451.4402680278736 291.7894809270699,413.4848201160996 S278.23248424265086,375.52937220432557 226.27049954371145,393.51521880486126 S174.30851484477205,411.50106540539696 192.58288863004236,499.1505327026981 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M182.11927519970206,499.91805847528013 C164.00492580808157,413.0361169505603 164.00492580808157,413.0361169505603 84.60246290404078,392.5828322413628 S5.199999999999999,372.1295475321653 5.199999999999999,479.46477376608254 S5.199999999999999,586.7999999999998 102.71681229566127,586.8 S200.23362459132255,586.8 182.11927519970206,499.91805847528013 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M419.01632250874417,513.4538702697257 C420.13403832891186,586.8000000000001 420.13403832891186,586.8000000000001 503.46701916445573,586.8000000000001 S586.7999999999996,586.8000000000001 586.7999999999996,541.0810938248264 S586.7999999999996,495.36218764965287 502.34930334428805,467.7349640945521 S417.8986066885765,440.10774053945136 419.01632250874417,513.4538702697257 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
        <path d="M408.61345838732524,513.3451602623403 C407.49408594402666,439.89032052468076 407.49408594402666,439.89032052468076 360.952268617622,448.2170184765361 S314.4104512912173,456.54371642839146 279.3882141183964,521.6718582141957 S244.3659769455754,586.7999999999998 327.0494038880996,586.7999999999998 S409.7328308306238,586.7999999999998 408.61345838732524,513.3451602623403 Z" stroke="red" stroke-width="0" fill="#221155" fill-opacity="0.2"/>
    </g>
</svg>

Color does not export

The Cell Color does not export. i am not sure if i am missing something, or if this is a legitimate issue. I think the later.
I have tried in 2 different Firefox based browsers and 1 chrome based.

Thanks

only supported import of SVG with a single path on the top level

I just discover this repo, this is very interesting but... I'd like to help by describing some issues and solutions I had wile testing.

Drag 'n drop

SVG

  1. I have tested with a simple circle or square with a specific size, default layer, nothing fancy from inkscape 1.0 but I received this error: only supported import of SVG with a single path on the top level

It worked when I saved the file as Optimized SVG, "inkscape svg" and "plain svg" does not
Not sure what options are important but It worked with:
image
image

  1. then I don't understand well the units because I don't get the result I'm looking for.
    I'm working in mm, so here is the square I'm testing with:
    image
    it's a 85/85mm page with a 80/80mm square centered.

The result is:
image

So I understand that the size in the page is maybe in pixels or without unit. That's fine, I just need to adjust accordingly.

image

But I'm not sure how it work then.
Why there is no seeds on top and left sides?

"only one file allowed" on Linux + Firefox/Chrome

Hi, thanks for your awesome tool!

After upgrading my PC you tool refused to accept pngs and svgs via drag'n'drop in Firefox and Chrome on Linux + KDE Plasma 6!

After a lot of head scratching and debugging I figured out that this problem is unrelated to your tool and that the real problems stems from the fact that my Linux switched from using X11 to Wayland. If you search for "Wayland firefox" you come across bugreports like this:

https://bugs.kde.org/show_bug.cgi?id=484018

KDE Plasma in Wayland does not support Drag and Drop operations from Dolphin to Chromium (and Firefox).

So there is basically nothing you can do on your side to fix it but I still decided to create this issue so that other people might find this report

(well, you could actually improve the error message by adding some additional code in onDragEvents() in /src/voronoi_app.js you can check if event.dataTransfer exist. If it is missing then there is a problem with the drag'n'drop functionality of your browser and you can alert with a better error message. But i am not sure if it is worth the trouble because hopefully this issue will be fixed in the next few weeks/months)

Circle function is cut off at the bottom

Thank you for this awesome tool.
The bottom of the circle tool is cut off :/ This happens on both websites. Also gets into svg export. Tried different browsers. Issue persists.

image

exported height limited to 60%

  • split view and export svg so that the export can have different properties
  • use different method for svg size on window
  • might relate to the vertical view feature

Server-side rendering?

This project offers some unique nice features in voronoi generation, but if I'm not wrong it's only for browser environment.

@wassfila Have you any hints to generate server side SVGs in a NodeJS environment? Maybe using jsdom?

My use case requires the generation of hundreds of SVG in bulk starting from computed seeds using a static site generator.

Thanks!

Random color assignment - code fragment

First, let me say that this project is awesome! Thanks for creating such an incredible tool for voronoi diagram creation.

Now then... the readme states that random color assignment is a goal. I might have time to look at the source and submit a pull request, but until then, I have a fairly easy way for end users to achieve it.

  1. create your voronoi diagram using the online voronoi editor
  2. export your diagram to SVG
  3. open the SVG in a new browser tab (I testested in Chrome, but should work in Firefox)
  4. open the developer tools (default hotkey is <ctl><shift>-I
  5. make sure you are in the "Console" tab/section of the developer tools
  6. paste the following snippet into the console, and hit enter to execute the command

document.querySelectorAll("path").forEach(function(userPath) {
userPath.setAttribute("fill", "hsl("+ Math.floor(Math.random() * Math.floor(255)) + ",90%,60%)");
userPath.setAttribute("fill-opacity", "40%");
})

This snippet should iterate through all the "path" objects in your document, and set the fill color to:

  • a random hue between 0 and 255
  • saturation of 90%
  • luminosity of 60%
  • opacity of 40%

This should be easy to modify to your liking, since the numbers are unique, and the attribute they affect should be clear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.