From e3b1e82cc817749afcce3f00edaf1eebd439be88 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 18 Apr 2021 17:01:09 +0800 Subject: [PATCH] add voronoi_taiwan --- examples/taiwan/voronoi_taiwan.scad | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/taiwan/voronoi_taiwan.scad diff --git a/examples/taiwan/voronoi_taiwan.scad b/examples/taiwan/voronoi_taiwan.scad new file mode 100644 index 00000000..3d30106e --- /dev/null +++ b/examples/taiwan/voronoi_taiwan.scad @@ -0,0 +1,40 @@ +use ; +use ; +use ; +use ; + +voronoi_taiwan(); + +module voronoi_taiwan() { + taiwan = shape_taiwan(120, distance = 1); + + n = 40; + xs = rands(-15, 15, n); + ys = rands(-30, 40, n); + pts = [ + for(i = [0:n - 1]) + let(p = [xs[i], ys[i]]) + if(in_shape(taiwan, p, true)) + p + ]; + + all = concat(taiwan, pts); + + cells = tri_delaunay(all, ret = "VORONOI_CELLS"); + for(i = [0:len(cells) - 1]) { + color(rands(0, 1, 3)) + translate(all[i]) + linear_extrude(2, scale = 0.8) + translate(-all[i]) + intersection() { + polygon(taiwan); + polygon(cells[i]); + } + } + + color("black") + linear_extrude(.75) + offset(1) + polygon(taiwan); + +} \ No newline at end of file