In [68]:
%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import random

LINE_WIDTH=2.5
MARKER_SIZE=10
MARKER_STYLE='.'
DOT_STYLE=':'
SOLID_STYLE='-'
FONT_SIZE=24
args = {"ls":SOLID_STYLE, "lw":LINE_WIDTH, "marker":MARKER_STYLE, "markersize":MARKER_SIZE}

def addLine(p1, p2, **kwargs):    
    data = zip(p1,p2)
    line = plt.Line2D(data[0], data[1], **kwargs)
    plt.gca().add_line(line)

Hex geometry

Equilibrium triangles

Hex indexing

Converting between flat indexing and cell indexing

Vertex buffers

Computing neighbors

Converting from pixel to hex

Generating labrynths

Shuffling array items in place

Vortex effect

Path following

Drawing lines

Line width is not generally supported in webGL. To draw lines with thickness greater than 1, you need to draw a poly ribbon

In [69]:
ax = plt.axes()

p1 = np.array([1,1])
p2 = np.array([10,6])
addLine(p1, p2, **args)

length = 3
dir = p2 - p1
n = np.array([-dir[1], dir[0]])
n = n / np.linalg.norm(n)

midpoint = p1 + 0.5 * dir
textpoint = midpoint + 2*n
ax.arrow(midpoint[0], midpoint[1], n[0], n[1], lw=2.5, head_width=0.1, head_length=0.1, fc='k', ec='k')
ax.text(textpoint[0], textpoint[1], ' $n$', fontsize=FONT_SIZE)
ax.text(p1[0], p1[1], ' $p_1$', fontsize=24)
ax.text(p2[0], p2[1], ' $p_2$', fontsize=24)

p1a = p1 + length * n
p1b = p1 - length * n

p2a = p2 + length * n
p2b = p2 - length * n

args["ls"] = DOT_STYLE
addLine(p1a, p1b, **args)
addLine(p2a, p2b, **args)
addLine(p1a,p2a, **args)
addLine(p1b,p2b, **args)

ax.text(p1a[0], p1a[1], ' $p_1^a$', fontsize=FONT_SIZE)
ax.text(p1b[0], p1b[1], ' $p_1^b$', fontsize=FONT_SIZE)
ax.text(p2a[0], p2a[1], ' $p_2^a$', fontsize=FONT_SIZE)
ax.text(p2b[0], p2b[1], ' $p_2^b$', fontsize=FONT_SIZE)

plt.axis([-2, 15, -4, 12])
plt.show()