Wolfram Research

Function Repository Resource:

HitomezashiStitchPattern

Source Notebook

Generate a Hitomezashi stitch pattern

Contributed by: Sander Huisman

ResourceFunction["HitomezashiStitchPattern"][{x1, x2, x3, }, {y1, y2, y3, }]

returns the lines of a Hitomezashi stitch pattern based on the Boolean values xi and yi.

ResourceFunction["HitomezashiStitchPattern"][n,m]

returns the lines of a Hitomezashi stitch pattern based on the integers, reals, or strings n and m.

Details

Hitomezashi stitch patterns are based on horizontal and vertical dashing patterns. Based on whether the dashing is 'odd' or 'even', the dashing is active on odd positions or even positions.
Inputs in the horizontal and vertical directions are either are a list of Boolean values, integers, reals or strings.
If items are True the line are positioned on the odd places, and if they are False they are placed on the even places.
Integers and real numbers are converted to base 2, after that 1s are converted to True, and 0s are converted to False.
Strings are fed to ToCharacterCode, even codes become True and off codes become False.

Examples

Basic Examples (2) 

Create simple Hitemezashi pattern:

In[1]:=
ResourceFunction[
 "HitomezashiStitchPattern"][{True, True, False, True, False, False, True}, {False, False, True, False, False}]
Out[1]=

Visualize it:

In[2]:=
% // Graphics
Out[2]=

Scope (4) 

Use integers rather than a list of booleans:

In[3]:=
ResourceFunction["HitomezashiStitchPattern"][1234, 5678] // Graphics
Out[3]=

Use real numbers instead:

In[4]:=
ResourceFunction["HitomezashiStitchPattern"][N[Pi, 30], N[E, 25]] // Graphics
Out[4]=

Use strings instead:

In[5]:=
ResourceFunction["HitomezashiStitchPattern"][
  "Claude Louis Marie Henri Navier", "Sir George Gabriel Stokes, 1st Baronet"] // Graphics
Out[5]=

Create a zig-zag pattern:

In[6]:=
ResourceFunction["HitomezashiStitchPattern"][
  ConstantArray[{True, False}, 10] // Flatten, ConstantArray[{True, False}, 10] // Flatten] // Graphics
Out[6]=

Possible Issues (3) 

Nothing might be returned if the input is too short:

In[7]:=
ResourceFunction["HitomezashiStitchPattern"][1, 1]
Out[7]=

Invalid input will return an empty line:

In[8]:=
ResourceFunction["HitomezashiStitchPattern"][<|a -> 2, b -> 3|>, 1]
Out[8]=

Non-True objects are turned into False using TrueQ:

In[9]:=
ResourceFunction[
  "HitomezashiStitchPattern"][{True, False, False, Xor[a, b]}, {True, False, True, True}] // Graphics
Out[9]=

Neat Examples (2) 

Create some simple patterns:

In[10]:=
GraphicsRow[
 Map[Graphics, {ResourceFunction["HitomezashiStitchPattern"][
    ConstantArray[{True, False}, 10] // Flatten, ConstantArray[{True, False}, 10] // Flatten], ResourceFunction["HitomezashiStitchPattern"][
    ConstantArray[{True, False}, 10] // Flatten, ConstantArray[{False, True}, 10] // Flatten],
   ResourceFunction["HitomezashiStitchPattern"][
    ConstantArray[{True, False}, 10] // Flatten, ConstantArray[False, 20]], ResourceFunction["HitomezashiStitchPattern"][
    ConstantArray[True, 10], ConstantArray[True, 10]]}, {1}]]
Out[10]=

Create a random pattern and color it in:

In[11]:=
p = ResourceFunction["HitomezashiStitchPattern"][
   RandomReal[{0, 1}, WorkingPrecision -> 30], RandomReal[{0, 1}, WorkingPrecision -> 20]];
Rasterize[
   Graphics[p, ImageSize -> 250, PlotRange -> CoordinateBounds[p[[1]], -0.5]], "Image", ImageResolution -> 144] // MorphologicalComponents // Colorize
Out[12]=

Resource History

Related Resources

License Information