# [GIF] Gerontocracy (Circular slices of a triangle)

Posted 4 years ago
3453 Views
|
5 Replies
|
11 Total Likes
| GerontocracyI'm extremely interested in using slices of an object to implicitly reconstruct the object itself. Of course, this is most obviously useful for high-dimensional objects, but it can also lead to some interesting visualizations of low-dimensional objects. Here are a couple of examples.Taking circle arc slices of an equilateral triangle isn't particularly interesting mathematically, but it still gives an interesting visual effect.Here's the code: cols = RGBColor /@ {"#118DF0", "#ECECDA", "#FF304F", "#0E2F56"} Module[{polygonvertices, n}, polygonvertices = {{0, 0}, {1, 0}, {1/2, Sqrt/2}}; n = 25; Manipulate[ Graphics[{Thickness[.02], CapForm["Round"], Flatten[Table[{cols[[i]], Circle[polygonvertices[[i]], r, {\[Pi] *2 (i - 1)/3, \[Pi] (2 i - 1)/3}]}, {r, s, 1.02, 1/n}, {i, 1, 3}], 1], EdgeForm[None], cols[], Polygon[{{3/2, 5}, {3/2, Sqrt/2}, {1/2, Sqrt/2}, {0, 0}, {-5, 0}, {-5, 5}}], Polygon[{{1/2, 5}, {1/2, Sqrt/2}, {1, 0}, {5, 0}}], Polygon[{{0, 0}, {0, 1}, {-5, 1}, {-5, -5}, {5, -5}, {5, 1}, {1, 1}, {1, 0}}]}, PlotRange -> {{-.1, 1.1}, {-0.16698729810778068, 1.0330127018922193}}, Background -> cols[], ImageSize -> 540], {s, 0., 1/n}] ] (The stupid Polygon objects are to blank out the region outside the triangle. As already mentioned, I would be very happy to learn a better way to approximate the functionality of RegionFunction in a Graphics object.) Answer
5 Replies
Sort By:
Posted 4 years ago
 This is beautiful, @Clayton Shonkwiler, thank you for sharing! In Graphics3D we have ClipPlanes to cut away portions of a 3D scene from the resulting view. You are right, in 2D (and 3D) we have RegionFunction but then you need to use Plot / Plot3D etc. - plotting functions. On the other hand I think Show and Overlay can combine objects with transparency holes. So you can create a template in a Plot-ing function (via RegionFunction), leading design in Graphics, and then block parts of the design with the template using Show or Overlay. Not sure how practical this is, just dwelling on ideas. Perhaps this might be of use too: Filling a polygon with a pattern of insets Answer
Posted 4 years ago
 I've already advocated a few times for a ClippingMask function, like illustrator/gimp/photoshop has. I think Mathematica really should have it. It probably already has such construct anyhow for the plotting functions. ClippingMask[object,mask] which shows parts of object (or objects) that are covered by mask. Where mask can be a polygon, region, bspline, rectangle, disk, ellipse, ....... Answer
Posted 4 years ago
 By lack of better, I am using the following combination of Overlay and SetAplhaChannel to mask images with square or round masks (illustrated with a Manipulate): Manipulate[Module[{im, sz, mask}, im = ImageResize[ExampleData[{"TestImage", "Lena"}], 350]; sz = ImageMeasurements[im, "Dimensions"]; mask = ImageResize[ ColorNegate@ Blur[Image[Graphics[RegularPolygon[pos, r, n], PlotRange -> 1]], blur], Most@sz]; Overlay[{Switch[bg, "black", mask, "white", Nothing], SetAlphaChannel[im, mask]}]], Grid[{ {Control[{{r, .95, "size"}, .5, 1.25, ImageSize -> Small}], Control[{{blur, 0}, 0, 50, ImageSize -> Small}]}, {Control[{{n, 4, "shape"}, {3 -> "triangle", 4 -> "square", 36 -> "round"}}], Control[{{pos, {0, 0}, "position"}, {-.5, -.5}, {.5, .5}, Slider2D, ImageSize -> 70}]}, {Control[{{bg, "black", "color"}, {"black", "white"}}], SpanFromAbove}}, Alignment -> {Left}, ItemSize -> 22]] here are some results:  Answer
Posted 4 years ago
 Indeed a beautiful GIF! Inspired by some of Vitaly's ideas, I came up with the following. I used Overlay and created a mask by means of a triangular AlphaChannel "hole" in the image. Hope this helps you to further improve this: Manipulate[ Module[{mask, cols}, cols = RGBColor /@ {"#118DF0", "#ECECDA", "#FF304F", "#0E2F56"}; mask = Image[ Graphics[SSSTriangle[1, 1, 1], PlotRange -> {{-.1, 1.1}, {-0.2, 1}}]]; Overlay[{ Graphics[{Thickness[.02], CapForm["Round"], Table[{cols[[i]], Circle[SSSTriangle[1, 1, 1][[-1, i]], r, {2 \[Pi] /3 (i - 1), \[Pi] (2 i - 1)/3}]}, {r, s, 1.02, 1/n}, {i, 3}]}], SetAlphaChannel[Image[Graphics[{}, Background -> cols[[-1]]]], mask]}]], {s, 0., 1/n}, {{n, 25}, None}]  Answer
Posted 4 years ago
 Thanks, that's definitely cleaner than my solution.It would still be nice to have a true RegionFunction replacement so that lines/curves/etc. don't just disappear under the background, but actually end. For example, I think this GIF would have been worse if the black lines were just disappearing under a light gray background rather than coming to rounded ends: Incidentally, I did try a ParametricPlot implementation of the GIF so that I could use RegionFunction, but the boundary-detection was too erratic to be useful. Here's what was produced: Notice how jumpy the circle arcs are near the boundary.(By the way, thanks @Vitaliy Kaurov for the link...it looks very interesting.) Answer