Wolfram Research

Function Repository Resource:

RandomKochCurve

Source Notebook

Generate a random Koch curve

Contributed by: Sander Huisman

ResourceFunction["RandomKochCurve"][{positiondist,widthdist,heightdist},n]

makes a random Koch curve based on the distributions positiondist,widthdist and heightdist, for n iterations.

ResourceFunction["RandomKochCurve"][{positiondist,widthdist,heightdist},{p1,p2,},n]

uses the starting points pi.

Details

The position, width, and height specifications determine the geometry:
Distributions can be any parametrized distribution such as UniformDistribution or NormalDistribution or can be a constant.
The three distributions are scaled from 0 to 1 to correspond to the length between the beginning and ending points.
ResourceFunction["RandomKochCurve"] returns a Line expression which can be visualized with Graphics.

Examples

Basic Examples (4) 

Generate a Koch curve:

In[1]:=
ResourceFunction["RandomKochCurve"][{NormalDistribution[], .5, .5}, 2]
Out[1]=

Generate a random Koch curve and display it:

In[2]:=
ResourceFunction[
  "RandomKochCurve"][{UniformDistribution[{0.3, 0.7}], UniformDistribution[{0.3, 0.4}], UniformDistribution[{0.2, 0.5}]}, 4] // Graphics
Out[2]=

Keep the position in the middle:

In[3]:=
ResourceFunction[
  "RandomKochCurve"][{1/2, NormalDistribution[1/3, 0.1], NormalDistribution[1/3, 0.1]}, 7] // Graphics
Out[3]=

Distributions don't have to be distributions but can be constant:

In[4]:=
ResourceFunction["RandomKochCurve"][{1/4, 0.2, 0.3}, 6] // Graphics
Out[4]=

Scope (1) 

Start with existing points:

In[5]:=
ResourceFunction[
  "RandomKochCurve"][{UniformDistribution[{0.4, 0.6}], UniformDistribution[{0.2, 0.5}], UniformDistribution[{0.2, 0.3}]}, {{0, 0}, {1, 1}, {1, 2}}, 6] // Graphics
Out[5]=

Properties and Relations (1) 

RandomKochCurve and KochCurve are related:

In[6]:=
g1 = {Blue, ResourceFunction[
    "RandomKochCurve"][{1/2, 1/3, Sqrt[3]/6}, {{0, 0.05}, {1, 0.05}}, 4]};
g2 = {Red, KochCurve[4]};
Graphics[{g1, g2}]
Out[6]=

Neat Examples (1) 

Create a forest:

In[7]:=
ResourceFunction[
  "RandomKochCurve"][{UniformDistribution[{0.3, 0.7}], 0.01, UniformDistribution[{0.2, 0.5}]}, 7] // Graphics
Out[7]=

Publisher

SHuisman

Version History

  • 1.0.0 – 28 June 2022

Related Resources

License Information