Braid

In [230]:
% matplotlib inline
from numpy import *
from matplotlib.pyplot import plot
import matplotlib.pyplot as plt
import numpy as np
In [231]:
epsilon = 0.2                          # gap size, in radians
gaps = [2*pi/12, 10*pi/12, 6*pi/12]    # . three curves .  positions of "under" gap
offsets = [0, 2*pi/3, 4*pi/3]          # .                 starting phas offset
colors = ['blue', 'green', 'red']      # .
#colors = ['black']*3
xs = [None]*3

figure = plt.figure(dpi=220, figsize=(8, 1))     # figsize (horizontal, vertical) inches
axis = figure.add_subplot(111)                   # 111 => x=y=1 of 1 plot

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsilon)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsilon, pi + gaps[which] - epsilon)     # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsilon, 2*pi)                      # third
    horizontal = 0
    for cycle in range(5):
        for section in range(3):                                      
            img, = axis.plot(xs[section] + horizontal, sin(xs[section] - offsets[which]), 
                          color=colors[which], linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')
plt.show()
In [232]:
# The woodbox I've been working on is 36 x 22 1/4 .


width = 36
height = 22.25
border = 2
scale = 0.2

cycles = 3
braid_radius = 2.5

side = 2.5
bottom = 5.0

hscale = (width - 2*side) / (cycles * 2 * pi)

epsi = 0.2
In [233]:
figure = plt.figure(dpi=220, figsize=(scale*(width+2*border), scale*(height+2*border)))
axis = figure.add_subplot(111) 

# edge
for (x,y) in (([0,width], [0,0]),
              ([width,width], [0,height]),
              ([width,0], [height,height]),
              ([0,0], [height,0])
             ):
    axis.plot(x,y, color='cyan', linewidth=1)

#axis.plot(xu, yu, color='magenta', linewidth=1)

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsi)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsi, pi + gaps[which] - epsi)        # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsi, 2*pi)                      # third
    horizontal = 0
    for cycle in range(cycles):
        for section in range(3):
            if 'all':    # or which==0 # or 1, or 2
                img, = axis.plot(side + hscale * (xs[section] + horizontal), 
                                 bottom + braid_radius * sin(xs[section] - offsets[which]), color='black', linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')

## uncomment to generate .svg
#plt.gca().set_position([0, 0, 1, 1])
#plt.savefig("braid.svg")

plt.show()
In [234]:
figure = plt.figure(dpi=220, figsize=(scale*(width+2*border), scale*(height+2*border)))
axis = figure.add_subplot(111) 

# edge
for (x,y) in (([0,width], [0,0]),
              ([width,width], [0,height]),
              ([width,0], [height,height]),
              ([0,0], [height,0])
             ):
    axis.plot(x,y, color='cyan', linewidth=1)

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsi)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsi, pi + gaps[which] - epsi)        # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsi, 2*pi)                      # third
    horizontal = 0
    for cycle in range(cycles):
        for section in range(3):
            if 'all':    # or which==0 # or 1, or 2
                img, = axis.plot(side + hscale * (xs[section] + horizontal), 
                                 bottom + braid_radius * sin(xs[section] - offsets[which]), color='black', linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')

## uncomment to generate .svg
plt.gca().set_position([0, 0, 1, 1])
plt.savefig("braid_all.svg")
In [235]:
figure = plt.figure(dpi=220, figsize=(scale*(width+2*border), scale*(height+2*border)))
axis = figure.add_subplot(111) 

# edge
for (x,y) in (([0,width], [0,0]),
              ([width,width], [0,height]),
              ([width,0], [height,height]),
              ([0,0], [height,0])
             ):
    axis.plot(x,y, color='cyan', linewidth=1)

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsi)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsi, pi + gaps[which] - epsi)        # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsi, 2*pi)                      # third
    horizontal = 0
    for cycle in range(cycles):
        for section in range(3):
            if which == 0:
                img, = axis.plot(side + hscale * (xs[section] + horizontal), 
                                 bottom + braid_radius * sin(xs[section] - offsets[which]), color='black', linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')

## uncomment to generate .svg
plt.gca().set_position([0, 0, 1, 1])
plt.savefig("braid_0.svg")

plt.show()
In [236]:
figure = plt.figure(dpi=220, figsize=(scale*(width+2*border), scale*(height+2*border)))
axis = figure.add_subplot(111) 

# edge
for (x,y) in (([0,width], [0,0]),
              ([width,width], [0,height]),
              ([width,0], [height,height]),
              ([0,0], [height,0])
             ):
    axis.plot(x,y, color='cyan', linewidth=1)

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsi)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsi, pi + gaps[which] - epsi)        # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsi, 2*pi)                      # third
    horizontal = 0
    for cycle in range(cycles):
        for section in range(3):
            if which == 1:
                img, = axis.plot(side + hscale * (xs[section] + horizontal), 
                                 bottom + braid_radius * sin(xs[section] - offsets[which]), color='black', linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')

## uncomment to generate .svg
plt.gca().set_position([0, 0, 1, 1])
plt.savefig("braid_1.svg")

plt.show()
In [237]:
figure = plt.figure(dpi=220, figsize=(scale*(width+2*border), scale*(height+2*border)))
axis = figure.add_subplot(111) 

# edge
for (x,y) in (([0,width], [0,0]),
              ([width,width], [0,height]),
              ([width,0], [height,height]),
              ([0,0], [height,0])
             ):
    axis.plot(x,y, color='cyan', linewidth=1)

for which in range(3):
    xs[0] = np.linspace(0, gaps[which] - epsi)                              # first horizontal section
    xs[1] = np.linspace(gaps[which] + epsi, pi + gaps[which] - epsi)        # second, between gaps
    xs[2] = np.linspace(pi + gaps[which] + epsi, 2*pi)                      # third
    horizontal = 0
    for cycle in range(cycles):
        for section in range(3):
            if which == 2:
                img, = axis.plot(side + hscale * (xs[section] + horizontal), 
                                 bottom + braid_radius * sin(xs[section] - offsets[which]), color='black', linewidth=3)
            img.set_solid_capstyle('round')
        horizontal += 2*pi

plt.axis('off')

## uncomment to generate .svg
plt.gca().set_position([0, 0, 1, 1])
plt.savefig("braid_2.svg")

plt.show()
In [ ]: