Skip to content

Instantly share code, notes, and snippets.

@lowteq
Last active April 28, 2021 15:59
Show Gist options
  • Save lowteq/55ff1be40e50aef99cefce97646aab94 to your computer and use it in GitHub Desktop.
Save lowteq/55ff1be40e50aef99cefce97646aab94 to your computer and use it in GitHub Desktop.
pattern to cube on blender
import bpy
def parser(data):
data = data.splitlines()
print(len(data))
print(len(data[0]))
return [[data[j][i] == "■" for i in range(len(data[0]))] for j in range(len(data))]
def createpattern(pat):
w = len(pat[0])
h = len(pat)
size = 1.0
offset = [(w-1)*size/2.0,(h-1)*size/2.0]
for i in range(w):
for j in range(h):
if pat[j][i]:
bpy.ops.mesh.primitive_cube_add(size=size,location=(size*i-offset[0],offset[1]-size*j,0))
x = parser("""\
■■□□■□□□■□■□■■■□□■□□
■□■■□■□■□■■■□□■■■□■□
□■□□□■■□□□■■□■□■□■□■
■□■□■□■■□■□■■□□■■■□■
■□□□■■□□■■□□□■□□□■■□
□□■■■□□■■□■□■□■□■□□■
□■□■□■□□□■■■□■■■□□■■
□■■□■□■■□■■■□■□■□■□■
■□□□■■□□□□■■■■□□■■■□
□□□■■□□□□□□■□□■□□■□■
■□■□□■□□■□□□□□□■■□□□
□■■■□□■■■■□□□□■■□□□■
■□■□■□■□■■■□■■□■□■■□
■■□□■■■□■■■□□□■□■□■□
■□□■□■□■□■□■■□□■■■□□
□■■□□□■□□□■■□□■■□□□■
■□■■■□□■■□■□■■□■□■□■
■□■□■□■□■■□□□■■□□□■□
□■□■■■□□■■■□■□■□■■□■
□□■□□■■■□■□■□□□■□□■■""")
createpattern(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment