Created
September 25, 2017 15:47
-
-
Save lauradean/cf2e100522de6a74bdc5f6576deb6213 to your computer and use it in GitHub Desktop.
Generate a grid of hexagons in blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import math | |
radius = .3 # long diagonal of hexagon | |
layers = 12 # number of rings of hexagons in grid | |
def makePrimitiveCircle(objName, v, r, f, loc, rot, lvl, layers=[0]): | |
bpy.ops.mesh.primitive_circle_add( | |
vertices=v, | |
radius=r, | |
fill_type=f, | |
view_align=False, | |
enter_editmode=False, | |
location=loc, | |
rotation=rot, | |
layers=[(i in layers) for i in range(20)]) | |
ob = bpy.context.active_object | |
ob.name = objName | |
ob.show_name = True | |
me = ob.data | |
me.name = objName + 'Mesh' | |
# give the hexagons a gradiated green hue | |
mat = bpy.data.materials.new("PKHG") | |
r = .05 * 1.2 ** n; | |
g = .1 * 1.2 ** n; | |
b = .05 * 1.2 ** n; | |
mat.diffuse_color = (r, g, b) | |
ob = bpy.context.selected_objects[0] | |
ob.active_material = mat | |
return ob | |
objs = bpy.data.objects | |
objs.remove(objs["Cube"], True) | |
n=0 | |
count=0; | |
letter=ord('a'); | |
start = ord('A') - 1 | |
a = chr(start + 1) | |
while (n <= layers): | |
count = 0 | |
x = 0 - n*math.sqrt(3)*radius | |
y = 0 | |
makePrimitiveCircle(chr(letter+n)+str(count), 6, radius, 'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(0,n): | |
x=x+math.sqrt(3)*radius/2; | |
y=y+radius*1.5; | |
makePrimitiveCircle(chr(letter+n)+str(count), 6, radius, 'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(0,n): | |
x=x+math.sqrt(3)*radius | |
makePrimitiveCircle(chr(letter+n)+str(count), 6, radius, 'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(0,n): | |
x=x+math.sqrt(3)*radius/2 | |
y=y-radius*1.5 | |
makePrimitiveCircle(chr(letter+n)+str(count),6,radius,'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(0,n): | |
x=x-math.sqrt(3)/2*radius | |
y=y-radius*1.5 | |
makePrimitiveCircle(chr(letter+n)+str(count),6,radius,'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(0,n): | |
x=x-math.sqrt(3)*radius | |
makePrimitiveCircle(chr(letter+n)+str(count),6,radius,'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
for i in range(1,n): | |
x=x-math.sqrt(3)*radius/2 | |
y=y+radius*1.5 | |
makePrimitiveCircle(chr(letter+n)+str(count),6,radius,'NGON', (x,y,0), (0,0,0), n) | |
count+=1; | |
n+=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment