Skip to content

Instantly share code, notes, and snippets.

@lauradean
Created September 29, 2017 19:09
Show Gist options
  • Save lauradean/c27e322e616510e022abbc98bf9c92da to your computer and use it in GitHub Desktop.
Save lauradean/c27e322e616510e022abbc98bf9c92da to your computer and use it in GitHub Desktop.
import bpy
import math
from mathutils import Vector, Matrix
radius = .3
layers = 12
height = .1
def makePrimitiveCircle(objRing, objNum, v, r, f, loc, rot, lvl, layers=[0]):
objName = objRing+objNum;
objType = 'grass';
if objRing == 'f':
if int(objNum)%5 == 0:
objType='dwelling1'
if objRing == 'g':
if (int(objNum)+1)%2 == 0 and (int(objNum))%3 != 0:
objType='dwelling1';
if objRing == 'h':
if (int(objNum)%7)-6 == 0 or (int(objNum)%7)-1 == 0:
objType='dwelling1';
if objRing == 'i':
if (int(objNum)%8)-3 == 0 or (int(objNum)%8)-5 == 0:
objType='dwelling2';
if objRing == 'j':
if (int(objNum)%9)-1 == 0 or (int(objNum)%9)-3 == 0 or (int(objNum)%9)-6 == 0 or (int(objNum)%9)-8 == 0:
objType='dwelling2';
if objRing == 'k':
if (int(objNum)%5) == 0 or (int(objNum)%5)-4 == 0 or (int(objNum)%5)-1 == 0:
objType='dwelling2';
if objType == 'dwelling1' or objType == 'dwelling2':
if objType == 'dwelling1':
d = height
if objType == 'dwelling2':
d = height * 2;
bpy.ops.mesh.primitive_cylinder_add(
vertices=v,
radius=r,
depth=d,
end_fill_type='NGON',
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 = objRing+objNum
ob.location += Vector( (0, 0, d/2) )
#ob.color = (100, 0, 0, 1)
ob.show_name = True
me = ob.data
me.name = objName + 'Mesh'
mat = bpy.data.materials.new("PKHG")
mat.diffuse_color = (1,1,1)
if objType == 'grass':
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.color = (100, 0, 0, 1)
ob.show_name = True
me = ob.data
me.name = objName + 'Mesh'
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