Wolfram Research

Function Repository Resource:

RandomMandala

Source Notebook

Make random mandala plots

Contributed by: Anton Antonov  |  Anton Antonov

ResourceFunction["RandomMandala"][]

generates a mandala graphic.

Details and Options

The mandalas made by ResourceFunction["RandomMandala"] are generated through rotational symmetry of a "seed segment."
ResourceFunction["RandomMandala"] accepts the same options as Graphics as well as the following options to specify different features of the seed segment generation and rotational symmetry order:
"RotationalSymmetryOrder"6a value k defining the rotation symmetry angle 2π/k
"Radius"10maximum radius of the seed segment generation points
"SymmetricSeed"Truewhether the seed should be symmetric
"NumberOfSeedElements"Automaticthe number of elements in a seed segment
"KeepGridPoints"Falseshould the grid points be shown
"ConnectingFunction"Randomhow to connect a grid point
"SeedFunction"Automatica function for drawing the seed segment
"ColorFunction"Nonehow to colorize the mandala
"FaceForm"{}face graphics directive for filled objects
"EdgeForm"{}edge graphics directive for filled objects
The option "ConnectionFunction" specifies what Graphics primitive function should be used to connect the grid points of the seed segment. If the value is Automatic then Polygon is used. If the value is Random then a random choice is made from the following: Line, Polygon, BezierCurve or FilledCurve[BezierCurve[#]]&.
The option "SeedFunction" specifies the function for drawing mandala's seed segment. If the value is Automatic, then the seed segment is drawn by taking into account the values of the options "Radius", "NumberOfSeedElements", "KeepGridPoints" and "ConnectingFunction".

Examples

Basic Examples (2) 

Here we generate a random mandala:

In[1]:=
SeedRandom[4243];
ResourceFunction["RandomMandala"][]
Out[2]=

Here we generate a mandala with different option settings:

In[3]:=
SeedRandom[1];
ResourceFunction["RandomMandala"]["RotationalSymmetryOrder" -> 7, "Radius" -> 12, "SymmetricSeed" -> False]
Out[4]=

Scope (2) 

There are two modes of making random mandalas: (i) single-mandala mode and (ii) multi-mandala mode. The multi-mandala mode is activated by giving the "Radius" option a list of positive reals.

Here are gray mandalas generated with the single-mandala mode:

In[5]:=
SeedRandom[54929];
Table[ResourceFunction["RandomMandala"]["Radius" -> 10], 4]
Out[6]=

Here are colorized mandalas generated with the single-mandala mode:

In[7]:=
SeedRandom[54929];
Table[ResourceFunction["RandomMandala"]["Radius" -> 10, ColorFunction -> ColorData["Rainbow"]], 4]
Out[8]=

Here are gray mandalas generated with a multi-mandala mode:

In[9]:=
SeedRandom[54929];
Table[ResourceFunction["RandomMandala"]["Radius" -> {7, 5, 3}], 4]
Out[10]=

Here are colorized mandalas generated with a multi-mandala mode:

In[11]:=
SeedRandom[54929];
Table[ResourceFunction["RandomMandala"]["Radius" -> {7, 5, 3}, ColorFunction -> "Rainbow"], 4]
Out[12]=

Options (15) 

ColorFunction (2) 

The function given to ColorFunction is run over Range[0,1,0.1] and the obtained colors are used to colorize the mandala. By default no colorizing is done and ColorFunctionNone.

ColorFunction can also take strings that are color schemes known by ColorData.

Here is a list of colorized mandalas using single-mandala mode:

In[13]:=
Table[SeedRandom[17]; ResourceFunction["RandomMandala"][ColorFunction -> ColorData[cf], PlotLabel -> cf], {cf, {"Rainbow", "SouthwestColors", "BrightBands",
    "DeepSeaColors"}}]
Out[13]=

Here are mandalas generated using multi-mandala mode:

In[14]:=
Table[SeedRandom[74]; ResourceFunction["RandomMandala"]["Radius" -> {7, 6, 4}, ColorFunction -> cf, PlotLabel -> cf], {cf, {"Rainbow", "SouthwestColors", "BrightBands",
    "DeepSeaColors"}}]
Out[14]=

ConnectingFunction (1) 

The option "ConnectingFunction" specifies which graphics primitive to use over the seed segment points:

In[15]:=
Table[(SeedRandom[263]; ResourceFunction["RandomMandala"]["ConnectingFunction" -> cf, PlotLabel -> cf]), {cf, {Line, Arrow, Polygon, BezierCurve, FilledCurve@*BezierCurve}}]
Out[15]=

EdgeForm (1) 

The option EdgeForm specifies directives for the edges of polygons or other filled graphics objects:

In[16]:=
SeedRandom[42];
ResourceFunction["RandomMandala"]["Radius" -> 8, "RotationalSymmetryOrder" -> 5, "ConnectingFunction" -> FilledCurve@*BezierCurve, EdgeForm -> {Red, Thick}]
Out[14]=

FaceForm (1) 

The option FaceForm specifies directives for the faces of polygons or other filled graphics objects:

In[17]:=
Table[(SeedRandom[8]; ResourceFunction["RandomMandala"]["Radius" -> {6, 8, 4}, ColorFunction -> "Rainbow", "ConnectingFunction" -> FilledCurve@*BezierCurve, PlotLabel -> Row[{"Opacity:", Spacer[3], op}], FaceForm -> {Opacity[op]}]), {op, {0.4, 0.6, 1}}]
Out[17]=

KeepGridPoints (1) 

The option "KeepGridPoints" specifies whether the points used to generate the seed segment should be kept:

In[18]:=
Table[(SeedRandom[163]; ResourceFunction["RandomMandala"]["KeepGridPoints" -> k, "NumberOfSeedElements" -> 3, "RotationalSymmetryOrder" -> 6, PlotLabel -> k]), {k, {True, False}}]
Out[18]=
In[19]:=
Table[(SeedRandom[163]; ResourceFunction["RandomMandala"]["KeepGridPoints" -> k, "NumberOfSeedElements" -> 5, "RotationalSymmetryOrder" -> 6, PlotLabel -> k]), {k, {True, False}}]
Out[19]=

NumberOfElements (1) 

The option "NumberOfElements" controls how may graphics elements are in the seed segment:

In[20]:=
Table[(SeedRandom[200]; ResourceFunction["RandomMandala"]["NumberOfSeedElements" -> n, "RotationalSymmetryOrder" -> 3, PlotLabel -> Row[{"n:", Spacer[2], n}]]), {n, 1, 6}]
Out[20]=
In[21]:=
Table[(SeedRandom[200]; ResourceFunction["RandomMandala"]["NumberOfSeedElements" -> n, "RotationalSymmetryOrder" -> 3, PlotLabel -> Row[{"n:", Spacer[2], n}]]), {n, 5, 20, 5}]
Out[21]=

If the value of "NumberOfElements" is Automatic in single-mandala mode, 6 elements are used; in multi-mandala mode, 3 elements are used (for each mandala).

Radius (2) 

In single-mandala mode the option "Radius" specifies the radius of the seed segment and the mandala:

In[22]:=
Table[(SeedRandom[226]; ResourceFunction["RandomMandala"]["Radius" -> r, PlotLabel -> Row[{"radius:", Spacer[2], r}], Frame -> True]), {r, 5, 20, 5}]
Out[22]=

If the value given to "Radius" is a list of positive numbers, then multi-mandala mode is used.

If "Radius"{r1,…,rk}, then for each ri, a mandala is made with radius ri and the mandalas are drawn upon each other according to their radii order:

In[23]:=
SeedRandom[98];
ResourceFunction["RandomMandala"]["Radius" -> Range[8, 2, -2]]
Out[21]=

Using the option ColorFunction, colorized mandalas are obtained:

In[24]:=
SeedRandom[98];
ResourceFunction["RandomMandala"]["Radius" -> Range[8, 2, -2], ColorFunction -> ColorData["Rainbow"]]
Out[25]=

RotationalSymmetryOrder (2) 

The "RotationalSymmetryOrder" option specifies how many copies of the seed segment comprise the mandala:

In[26]:=
Table[(SeedRandom[122]; ResourceFunction["RandomMandala"]["RotationalSymmetryOrder" -> a, PlotLabel -> Row[{"order:", Spacer[2], a}]]), {a, {2, 3, 4, 6}}]
Out[26]=
In[27]:=
Table[(SeedRandom[122]; ResourceFunction["RandomMandala"]["RotationalSymmetryOrder" -> a, "SymmetricSeed" -> False, PlotLabel -> Row[{"order:", Spacer[2], a}]]), {a, {2, 3, 4, 6}}]
Out[27]=

If both "Radius" and "RotationalSymmetryOrder" are given lists of numbers, then the corresponding elements in those are paired to make the specifications of the colorized mandalas:

In[28]:=
Table[
 SeedRandom[122];
 ResourceFunction["RandomMandala"]["Radius" -> {8, 4}, "RotationalSymmetryOrder" -> rs, "ConnectingFunction" -> FilledCurve@*BezierCurve, ColorFunction -> "Rainbow", FaceForm -> {Opacity[0.7]}, EdgeForm -> {White, Opacity[1]}, PlotLabel -> Row[{"order:", Spacer[2], rs}]], {rs, {{4, 2}, {6, 3}, {5, 10}}}]
Out[28]=

SeedFunction (3) 

The option "SeedFunction" specifies the function for drawing mandala's seed segment. If the value is Automatic, then the seed segment is drawn by taking into account the values of the options "Radius", "NumberOfSeedElements", "KeepGridPoints" and "ConnectingFunction".

Here is a custom seed function that places circles or disks at random points within the segment that corresponds to radius and angle:

In[29]:=
Clear[CustomSeed];
CustomSeed[radius_, angle_, n_Integer : 10, connectingFunc_ : Polygon,
    keepGridPoints_ : False, opts : OptionsPattern[]] :=
  Block[{cf = connectingFunc},
   If[! MemberQ[{Circle, Disk}, cf], cf = Circle];
   Flatten@Table[
     cf[p, radius*RandomReal[{0.01, 0.2}]],
     {p, RandomPoint[Disk[{0, 0}, radius, {0, angle}], n]}]
   ];

Here are single-mandala mode mandalas made with the custom seed segment function defined above:

In[30]:=
SeedRandom[344];
Grid@Table[
  ResourceFunction["RandomMandala"][
   "SeedFunction" -> CustomSeed], {2}, {3}]
Out[31]=

Here are multi-mandala mode colorized mandalas (with two seed elements and randomly selected connecting functions):

In[32]:=
SeedRandom[344];
Grid@Table[
  ResourceFunction["RandomMandala"]["Radius" -> {10, 6, 3}, "SeedFunction" -> CustomSeed, "ConnectingFunction" -> RandomChoice[{Circle, Disk}], "NumberOfSeedElements" -> 2, "ColorFunction" -> "DarkRainbow"], {2}, {3}]
Out[33]=

SymmetricSeed (1) 

The option "SymmetricSeed" specifies whether the seed segment should be symmetric:

In[34]:=
Table[(SeedRandom[122]; ResourceFunction["RandomMandala"]["SymmetricSeed" -> s, PlotLabel -> s]), {s, {True, False}}]
Out[34]=

Properties and Relations (2) 

Using combinations of settings for ColorFunction, EdgeForm and FaceForm can produce certain more nuanced mandala effects than, say, just using ColorFunction:

In[35]:=
Table[
 SeedRandom[89];
 ResourceFunction["RandomMandala"]["Radius" -> {8, 6, 4}, "RotationalSymmetryOrder" -> {12, 6, 3}, "ConnectingFunction" -> FilledCurve@*BezierCurve, ColorFunction -> "RustTones", ImageSize -> 300, opts], {opts, {{FaceForm -> {Opacity[0.7]}, EdgeForm -> {White, Thickness[0.006], Opacity[1]}}, {}}}]
Out[35]=

RandomMandala can be used in more or less the same way as the resource function RandomScribble; here RandomMandala is used with the resource function TexturizePolygons:

In[36]:=
SeedRandom[5353];
ResourceFunction["TexturizePolygons"][{"Dodecahedron", "Net"}, Table[ResourceFunction["RandomMandala"][
   ColorFunction -> ColorData["Rainbow"]], 4], "Granularity" -> "Polygon"]
Out[27]=

Here the resource function RandomScribble is used with the resource function TexturizePolygons:

In[37]:=
SeedRandom[2323];
ResourceFunction["TexturizePolygons"][{"Dodecahedron", "Net"}, Table[ResourceFunction["RandomScribble"][
   "NumberOfStrokes" -> RandomInteger[{600, 820}, 2], ColorFunction -> ColorData["Rainbow"]], 4], "Granularity" -> "Polygon"]
Out[38]=

Possible Issues (1) 

If the specified rotational symmetry order is not an integer, then the produced mandalas will appear "open":

In[39]:=
SeedRandom[23];
rotOrders = RandomReal[{0, 10}, 5]
Out[27]=
In[40]:=
Table[(SeedRandom[32]; ResourceFunction["RandomMandala"][
   "RotationalSymmetryOrder" -> r]), {r, rotOrders}]
Out[40]=
In[41]:=
Table[(SeedRandom[1]; ResourceFunction["RandomMandala"][
   "RotationalSymmetryOrder" -> r]), {r, rotOrders}]
Out[41]=

Neat Examples (8) 

Random mandalas (3) 

A table of random mandalas:

In[42]:=
SeedRandom[342]; Multicolumn[
 Table[ResourceFunction["RandomMandala"][
   "RotationalSymmetryOrder" -> RandomChoice[{3, 6, 12}], "SymmetricSeed" -> RandomChoice[{True, False}], ImageSize -> Tiny],
   36], 6]
Out[42]=

A table of random colorized mandalas:

In[43]:=
SeedRandom[474]; Multicolumn[
 Table[ResourceFunction["RandomMandala"][
   "Radius" -> Reverse[Range[RandomChoice[{3, 4, 5, 6}]]], "NumberOfSeedElements" -> RandomChoice[{2, 3, 4}], "RotationalSymmetryOrder" -> RandomChoice[{3, 4, 5, 6, 7}], ColorFunction -> "DarkRainbow", "ConnectingFunction" -> FilledCurve@*BezierCurve, "SymmetricSeed" -> True, FaceForm -> {Opacity[0.7]}, EdgeForm -> {LightBlue, Opacity[1]}, ImageSize -> 150], 25], 6]
Out[43]=

A table of "open" colorized mandalas:

In[44]:=
n = 36;
Magnify[Multicolumn[
  Map[BlockRandom[SeedRandom[24]; ResourceFunction["RandomMandala"]["RotationalSymmetryOrder" -> #,
       ColorFunction -> ColorData["DeepSeaColors"]]] &, RandomReal[{2, 4}, n]], 6], 0.5]
Out[27]=

Colored mandala images by blending (4) 

Make a list of random mandalas:

In[45]:=
SeedRandom[6567];
mandalas = Table[ResourceFunction["RandomMandala"][], 36];
Magnify[mandalas, 0.3]
Out[40]=

Make images of the generated mandala graphics:

In[46]:=
AbsoluteTiming[
 mandalaImages = Map[Image[#, ImageSize -> {400, 400}, ColorSpace -> "Grayscale"] &,
     mandalas];
 ]
Out[46]=

Pick mandala images at random and blend them using a set of coloring schemes:

In[47]:=
SeedRandom[3488];
AbsoluteTiming[
 directBlendingImages = Table[
    RemoveBackground@
     ImageAdjust[
      Blend[Colorize[#, ColorFunction -> RandomChoice[{"IslandColors", "FruitPunchColors", "AvocadoColors", "Rainbow"}]] & /@ RandomChoice[mandalaImages, 4], RandomReal[1, 4]]], 12];
 ]
Out[48]=

Make a collage:

In[49]:=
ImageCollage[directBlendingImages, Background -> White, ImagePadding -> 3, ImageSize -> 200]
Out[49]=

Mandalas made with random scribbles (1) 

Here are mandalas made with the repository function RandomScribble:

In[50]:=
SeedRandom[67];
Clear[ScribblesSeed];
Options[ScribblesSeed] = Options[ResourceFunction["RandomScribble"]];
ScribblesSeed[radius_, angle_, n_Integer : 10, args___, opts : OptionsPattern[]] :=
 Block[{t},
  Table[
   t = ResourceFunction["RandomScribble"][opts][[1]];
   t = GeometricTransformation[t, ScalingMatrix[radius*{1, 1}/RandomReal[{4, 12}]]];
   GeometricTransformation[t, TranslationTransform[p]],
   {p, RandomPoint[Disk[{0, 0}, radius, {0, angle}], n]}]
  ]; Multicolumn[
 Table[ResourceFunction["RandomMandala"][
   "RotationalSymmetryOrder" -> RandomChoice[{5, 6, 7, 12}], "SymmetricSeed" -> False, "SeedFunction" -> (ScribblesSeed[##, "NumberOfStrokes" -> {200, 200}, "RotationAngle" -> {-\[Pi]/6, 2 \[Pi] - \[Pi]/7}, "OrderedStrokePoints" -> True, ColorFunction -> "AlpineColors",
        "EnvelopeFunctions" -> Automatic] &), "NumberOfSeedElements" -> RandomChoice[{10, 6, 3}], ImageSize -> 150], 25], 6]
Out[46]=

Resource History

Related Resources

Author Notes

The Python RandomMandala package was implemented in order to compare it with this repository function (and, hence, compare Python and the Wolfram Language).

License Information