There are automatic Voronoi filters or ways to get a Voronoi "effect" for images. See Wolfram Demonstration or another Wolfram Demonstration But I want to do this interactively by determining with the mouse which areas of the image need more or less intense splitting into Voronoi polygons. To get something like this:
To achieve this, I first wrote a function to split any Polygon into a number of Voronoi polygons:
voronoiFy[polygon_, n_] :=
Module[{sites, bounds, vm}, SeedRandom[12345];
sites = RandomPoint[polygon, n];
bounds = MinMax /@ Transpose @@ polygon;
vm = VoronoiMesh[sites, bounds];
MeshPrimitives[vm, 2]]
and then, I integrated this into a Manipulate that uses a Locator to select a polygon and subsequently split it.
Manipulate[
Quiet@Module[{polys, activePoly, polys1},(*SeedRandom[1236];*)
polys = voronoiFy[Polygon[{{0., 0.}, {0, 1}, {1, 1}, {1, 0}}],
n1];
activePoly = SelectFirst[polys, RegionMember[#, pt] &];
polys1 =
Map[RegionIntersection[#, activePoly] &,
voronoiFy[activePoly, n2]];
Graphics[{FaceForm[],
EdgeForm[{AbsoluteThickness[1], Black}], polys,
EdgeForm[{AbsoluteThickness[2], Red}], activePoly, polys1}]],
{{pt, {.55, .5}}, Locator, LocatorRegion -> Full, Appearance -> None},
{{n1, 16}, Range[6, 24]},
{{n2, 12}, Range[4, 16]}, Deployed -> True,
SynchronousUpdating -> True, TrackedSymbols :> {pt, n1, n2}]
This gives at first this (without any error or pink colouring):
But when I select with the Locator another polygon, I get the desired result but only after a flashing pink intermediate image. I tried to catch the error and it says "Voronoi Mesh is not a Graphics Primitive..." I feel it has something to do with the evaluation order but I tried an Evaluate at all possible positions without any result: the pink flash keeps on annoying. Can somebody give a possible solution?