Skip to content

Instantly share code, notes, and snippets.

@jlaura
Created February 26, 2014 22:23
Show Gist options
  • Save jlaura/9239957 to your computer and use it in GitHub Desktop.
Save jlaura/9239957 to your computer and use it in GitHub Desktop.
import math
%pylab inline
def createhex(xoff=1,yoff=1):
A = (math.cos(math.radians(30)), math.sin(math.radians(30)))
B = (math.cos(math.radians(90)), sin(math.radians(90)))
C = (math.cos(math.radians(150)), sin(math.radians(150)))
D = (math.cos(math.radians(210)), sin(math.radians(210)))
E = (math.cos(math.radians(270)), sin(math.radians(270)))
F = (math.cos(math.radians(330)), sin(math.radians(330)))
G = (math.cos(math.radians(30)), math.sin(math.radians(30)))
x,y = zip(A,B,C,D,E,F,G)
x = [i + xoff for i in x]
y = [i + yoff for i in y]
return x,y
figsize(8,8)
xoffset = math.cos(math.radians(30))
yoffset = math.sin(math.radians(30))
for i in range(20):
for j in range(20):
xoff = j * xoffset * 2
if i % 2 != 0:
xoff += xoffset
yoff = i * yoffset * 3
x,y = createhex(xoff, yoff)
plt.plot(x,y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment