Wolfram Research

Function Repository Resource:

RandomScribble

Source Notebook

Make a random scribble graphic

Contributed by: Anton Antonov

ResourceFunction["RandomScribble"][]

generates a scribble graphic.

Details and Options

The scribbles made by ResourceFunction["RandomScribble"] are generated using Bezier curves through random points.
ResourceFunction["RandomScribble"] accepts the same options as Graphics as well as the following options to specify the scribble elements:
"ColorFunction"Automatichow to colorize the scribble
"ConnectingFunction"BezierCurvehow to make the scribble strokes
"EnvelopeFunctions"Nonefunctions for the bottom and top envelopes of the scribble
"NumberOfStrokes"120number of scribble strokes
"OrderedStrokePoints"Truewhether to order the stroke end points
"RotationAngle"Automaticangle used to rotate the scribble
PlotStyle{}plot styles used to draw the scribble
There are two modes, single-scribble and multi-scribble. The multi-scribble mode is activated by giving the option "NumberOfStokes" a list of positive integers or by giving the option "RotationAngle" a list of reals.
For the default ColorFunctionAutomatic, in single-scribble mode no colorizing is done and in multi-scribble mode GrayLevel is used.
The function given to ColorFunction is run over Range[0,1,0.1] and the obtained colors are used to colorize the scribble.
Without the use of envelop functions, the random scribbles are generated within the square [-1,1]2.

Examples

Basic Examples (3) 

Generate a random scribble:

In[1]:=
SeedRandom[12];
ResourceFunction["RandomScribble"][]
Out[2]=

Generate a scribble with different option settings:

In[3]:=
SeedRandom[1];
ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 200, "RotationAngle" -> \[Pi]/6, PlotStyle -> {Orange, AbsoluteThickness[3]}]
Out[4]=

Generate a "cross" scribble:

In[5]:=
SeedRandom[231];
ResourceFunction["RandomScribble"]["NumberOfStrokes" -> {140, 200}, "RotationAngle" -> {-\[Pi]/6, \[Pi]/6}, ColorFunction -> "LakeColors", PlotStyle -> Directive[{AbsoluteThickness[2]}]]
Out[6]=

Scope (3) 

Here are gray-level and colorized scribbles generated with single-scribble mode:

In[7]:=
SeedRandom[54929];
Table[ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 50], 4]
Out[8]=
In[9]:=
SeedRandom[54929];
Table[ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 50, ColorFunction -> ColorData["Rainbow"]], 4]
Out[10]=

Here are gray-level and colorized scribbles generated using multi-scribble mode:

In[11]:=
SeedRandom[54929];
Table[ResourceFunction["RandomScribble"][
  "NumberOfStrokes" -> {50, 60, 45}, "RotationAngle" -> Automatic], 4]
Out[12]=
In[13]:=
SeedRandom[54929];
Table[ResourceFunction["RandomScribble"][
  "NumberOfStrokes" -> {50, 60, 45}, "RotationAngle" -> Automatic, ColorFunction -> "Rainbow"], 4]
Out[14]=

Make "orderless" scribbles with fill-ins:

In[15]:=
SeedRandom[13];
Table[ResourceFunction["RandomScribble"][
  "ConnectingFunction" -> FilledCurve@*BezierCurve, "NumberOfStrokes" -> {30}, "OrderedStrokePoints" -> False], 4]
Out[16]=

Options (13) 

ColorFunction (2) 

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

Here are colorized scribbles generated using single-scribble mode:

In[17]:=
Table[SeedRandom[74]; ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 200, ColorFunction -> cf, PlotLabel -> cf], {cf, {Automatic, GrayLevel, "BrightBands", "DeepSeaColors"}}]
Out[17]=

Here are scribbles generated using multi-scribble mode:

In[18]:=
Table[SeedRandom[74]; ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 10*{7, 6, 4},
   ColorFunction -> cf, PlotLabel -> cf], {cf, {Automatic, GrayLevel, "BrightBands", "DeepSeaColors"}}]
Out[18]=

ConnectingFunction (1) 

The option "ConnectingFunction" specifies which graphics primitive to be used between the scribble points:

In[19]:=
lsConFuncs = {Line, Arrow, Polygon, BezierCurve, FilledCurve@*BezierCurve};
Table[(SeedRandom[263]; ResourceFunction["RandomScribble"]["ConnectingFunction" -> cf, "NumberOfStrokes" -> 16, "OrderedStrokePoints" -> False, PlotLabel -> cf]), {cf, lsConFuncs}]
Out[18]=

EnvelopeFunctions (2) 

The option "EnvelopeFunctions" specifies functions for the bottom and top envelope curves within which the scribble is drawn. If only one function is given, say F, then that function is considered to be for the top curve and bottom curve function is derived as (-F[#]&):

In[20]:=
SeedRandom[3];
Table[ResourceFunction["RandomScribble"]["NumberOfStrokes" -> 300, "EnvelopeFunctions" -> ef, "RotationAngle" -> 0, ColorFunction -> "Rainbow", PlotLabel -> Row[{ef}]], {ef, {None, Automatic, Sin, {-Abs[#]^(1/2) &, Exp}}}]
Out[18]=

If the envelope functions produce complex numbers, the real parts are taken:

In[21]:=
SeedRandom[5];
ResourceFunction["RandomScribble"][
 "EnvelopeFunctions" -> {Log10, Sqrt}, "NumberOfStrokes" -> 200, PlotLabel -> {Log10, Sqrt}, Frame -> True]
Out[22]=

NumberOfStrokes (2) 

The option "NumberOfStrokes" controls how many segments the scribble has:

In[23]:=
SeedRandom[122];
Table[ResourceFunction["RandomScribble"]["NumberOfStrokes" -> n, PlotLabel -> Row[{"n:", Spacer[3], n}]], {n, {10, 100, 500}}]
Out[18]=

If the option "NumberOfStrokes" is given a list of positive integers, then multi-scribble graphics are generated:

In[24]:=
SeedRandom[18];
ResourceFunction["RandomScribble"]["NumberOfStrokes" -> Table[120, 3]]
Out[25]=

OrderedStrokePoints (1) 

The option "OrderedStrokePoints" controls whether the scribble should be more uniform or completely random:

In[26]:=
Table[ResourceFunction["RandomScribble"]["OrderedStrokePoints" -> n, PlotLabel -> Row[{"ordered:", Spacer[3], n}]], {n, {True, False}}]
Out[26]=

RotationAngle (3) 

The option "RotationAngle" specifies the angle by which the scribble is rotated:

In[27]:=
SeedRandom[12];
Table[ResourceFunction["RandomScribble"]["RotationAngle" -> a, PlotLabel -> Row[{"rotation angle:", Spacer[3], a}]], {a, -\[Pi]/
   6, \[Pi]/2, \[Pi]/6}]
Out[18]=

If the option "RotationAngle" is given a list of reals, then multi-scribble graphics are generated:

In[28]:=
SeedRandom[24];
ResourceFunction["RandomScribble"][
 "RotationAngle" -> {0, \[Pi]/4, -\[Pi]/4}]
Out[29]=

In multi-scribble mode, if the value of "RotationAngle" is Automatic, then the generated scribbles are placed over a regular set of rotation angles. If the option value Random is given, then the rotation angles are random:

In[30]:=
SeedRandom[23];
Table[
 ResourceFunction["RandomScribble"][
  "NumberOfStrokes" -> Table[100, 3], "RotationAngle" -> a, ColorFunction -> "DarkRainbow", PlotLabel -> Row[{"rotation angle:", Spacer[3], a}]], {a, {Automatic, Random}}]
Out[31]=

PlotStyle (2) 

With the option PlotStyle, different stylings of the scribble drawing can be specified:

In[32]:=
SeedRandom[23];
Table[ResourceFunction["RandomScribble"]["RotationAngle" -> \[Pi]/4, PlotStyle -> st, PlotLabel -> ColumnForm[{"styling:", st}]], {st, {Blue, {Orange, AbsoluteThickness[5]}, {Red, Dashed}}}]
Out[18]=

In multi-scribble mode, colors specified in PlotStyle are replaced by the colors generated with the option ColorFunction:

In[33]:=
SeedRandom[67];
ResourceFunction["RandomScribble"]["RotationAngle" -> {0, \[Pi]/4}, ColorFunction -> "Pastel", PlotStyle -> Directive[{Orange, AbsoluteThickness[3]}]]
Out[34]=

Applications (4) 

Combine two colorized single-mode scribbles into a "cross" scribble:

In[35]:=
SeedRandom[98];
Show[MapThread[
  ResourceFunction["RandomScribble"]["NumberOfStrokes" -> #1, "RotationAngle" -> #2, ColorFunction -> "AvocadoColors", PlotStyle -> AbsoluteThickness[2]] &, {{140, 200}, {5 \[Pi]/6, \[Pi]/6}}]]
Out[18]=

Generate a colorized single-mode scribble with a restricted range of a given color scheme and compare it with a scribble that uses the full color scheme range:

In[36]:=
colorScheme = "WatermelonColors";
restrictedColorFunc = ColorData[colorScheme][Rescale[#, {0, 1}, {0.3, 0.6}]] &;
MapThread[
 (SeedRandom[7];
   ResourceFunction["RandomScribble"][ColorFunction -> #1, PlotStyle -> AbsoluteThickness[3], PlotLabel -> #2]) &,
 {{restrictedColorFunc, "WatermelonColors"}, {"Restricted color range", "Full color range"}}]
Out[33]=

Add scribbles to an image:

In[37]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e225acb7-87e4-4fbb-82ee-a68eccf4fe32"]
Out[38]=

Display the elements of a matrix using scribbles:

In[39]:=
mat = {{1, -1, 1, 1, -1}, {-1, -1, -1, 1, 1}, {1, 1, 1, -1, 1}, {-1, 1, -1, 1, -1}, {1, 1, 1, -1, -1}};
MatrixForm[mat]
Out[18]=

Here is the "scribble representation" of the matrix:

In[40]:=
SeedRandom[23];
Magnify[Grid[mat /. {
    -1 :> ResourceFunction["RandomScribble"][
      "EnvelopeFunctions" -> Automatic, "NumberOfStrokes" -> 200, "RotationAngle" -> \[Pi]/4, ColorFunction -> "SiennaTones", PlotStyle -> {AbsoluteThickness[3]}], 1 :> ResourceFunction["RandomScribble"][
      "EnvelopeFunctions" -> Automatic, "NumberOfStrokes" -> 200, "RotationAngle" -> \[Pi]/4, ColorFunction -> "AvocadoColors", PlotStyle -> {AbsoluteThickness[3]}]}, Dividers -> All], 0.3]
Out[41]=

Properties and Relations (2) 

Some of the implementation details can be illustrated with appropriate comparison tables. This coloring-versus-connecting table illustrates how the coloring of singe-mode scribbles is implemented:

In[42]:=
lsConFuncs = {Arrow, Polygon, BezierCurve, FilledCurve@*BezierCurve};
lsColSpecs = {None, "Rainbow"};
tbl = Table[(SeedRandom[263]; ResourceFunction["RandomScribble"]["ConnectingFunction" -> cf, "NumberOfStrokes" -> 20, "OrderedStrokePoints" -> True, ColorFunction -> col]), {col, lsColSpecs}, {cf, lsConFuncs}];
Grid[
 Transpose[
  Join[{Prepend[Rotate[#, \[Pi]/2] & /@ lsColSpecs, ""]}, Transpose[Prepend[tbl, lsConFuncs]]]],
 Dividers -> All, FrameStyle -> Gray
 ]
Out[43]=

RandomScribble can be used in more or less the same way as the resource function RandomMandala. Here, RandomScribble is used with the resource function TexturizePolygons:

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

Here, the resource function RandomMandala is used with the resource function TexturizePolygons:

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

Possible Issues (2) 

Specify a constant color function to use the same color for all scribbles in multi-scribble mode:

In[47]:=
SeedRandom[43];
ResourceFunction["RandomScribble"]["NumberOfStrokes" -> {140, 200}, "RotationAngle" -> {-\[Pi]/6, \[Pi]/6}, ColorFunction -> (Blue &)]
Out[18]=

Alternatively, specify ColorFunction to be None and PlotStyle to have the desired color:

In[48]:=
SeedRandom[43];
ResourceFunction["RandomScribble"]["NumberOfStrokes" -> {140, 200}, "RotationAngle" -> {-\[Pi]/6, \[Pi]/6}, ColorFunction -> None, PlotStyle -> Blue]
Out[49]=

Neat Examples (3) 

A table of random scribbles using the "RedBlueTones" color scheme and a regular set of rotation angles:

In[50]:=
SeedRandom[872]; Multicolumn[
 Table[ResourceFunction["RandomScribble"][
   "NumberOfStrokes" -> RandomInteger[{120, 180}], "OrderedStrokePoints" -> True, "RotationAngle" -> a, ColorFunction -> "RedBlueTones", PlotStyle -> Directive[{AbsoluteThickness[RandomReal[{1.5, 5}]]}], ImageSize -> Tiny], {a, -\[Pi]/3, \[Pi]/
    3, (2 \[Pi]/3)/(36 - 1)}], 6, Dividers -> All, Appearance -> "Horizontal"]
Out[50]=

A table of random multi-scribble graphics:

In[51]:=
SeedRandom[123]; Multicolumn[
 Table[ResourceFunction["RandomScribble"][
   "NumberOfStrokes" -> RandomInteger[{90, 120}, RandomInteger[{2, 3}]], "RotationAngle" -> RandomChoice[{Random, Automatic}], "OrderedStrokePoints" -> RandomChoice[{1, 6} -> {False, True}], ColorFunction -> RandomChoice[{3, 3, 1} -> {"Rainbow", "DarkBands", GrayLevel}], PlotStyle -> Directive[{AbsoluteThickness[RandomReal[{1.3, 5}]], Opacity[0.8]}], ImageSize -> Tiny], 36], 6, Dividers -> All]
Out[51]=

A table of random scribbles with unordered stroke points and fill-ins:

In[52]:=
SeedRandom[2]; Multicolumn[
 Table[ResourceFunction["RandomScribble"][
   "NumberOfStrokes" -> RandomInteger[{15, 20}], "OrderedStrokePoints" -> False, "ConnectingFunction" -> RandomChoice[{2, 6} -> {Polygon, FilledCurve@*BezierCurve}], ColorFunction -> None, ImageSize -> Tiny], 36], 6, Dividers -> All]
Out[52]=

Publisher

Anton Antonov

Version History

  • 2.1.0 – 06 January 2021

Related Resources

License Information