0

我想使用以螺旋图案构造的 XYZ 坐标创建六边形网格。这是我当前的代码,它产生了一个由下面的红色箭头描绘的网格。我的问题区域被圈出。而不是从 [-1,0,1] 到 [0,-2,2] 我需要从 [-1,0,1] 到 [-1,-1,2] (沿着蓝线) .

螺旋

完整的代码出现在哈希线下方 - 我正在 Blender 2.65a 中创建可视化

radius = 11 # determines size of field
deltas = [[1,0,-1],[0,1,-1],[-1,1,0],[-1,0,1],[0,-1,1],[1,-1,0]]
hex_coords = []
for r in range(radius):
    x = 0
    y = -r
    z = +r
    points = x,y,z
    hex_coords.append(points)
    for j in range(6):
        if j==5:
            num_of_hexas_in_edge = r-1
        else:
            num_of_hexas_in_edge = r
        for i in range(num_of_hexas_in_edge):
            x = x+deltas[j][0]
            y = y+deltas[j][1]
            z = z+deltas[j][2] 
            plot = x,y,z           
            hex_coords.append(plot)

-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# -

import bpy


FOXP2 = '''
CTTGAACCTTTGTCACCCCTCACGTTGCACACCAAAGACATACCCTAGTGATTAAATGCTGATTTTGTGT
ACGATTGTCCACGGACGCCAAAACAATCACAGAGCTGCTTGATTTGTTTTAATTACCAGCACAAAATGCC
CAATTCCTCCTCGACTACCTCCTCCAACACTTCCAAAGCATCACCACCAATAACTCATCATTCCATAGTG
AATGGACAGTCTTCAGTTCTAAGTGCAAGACGAGACAGCTCGTCACATGAGGAGACTGGGGCCTCTCACA
CTCTCTATGGCCATGGAGTTTGCAAATGGCCAGGCTGTGAAAGCATTTGTGAAGATTTTGGACAGTTTTT
AAAGCACCTTAACAATGAACACGCATTGGATGACCGAAGCACTGCTCAGTGTCGAGTGCAAATGCAGGTG
GTGCAACAGTTAGAAATACAGCTTTCTAAAGAACGCGAACGTCTTCAAGCAATGATGACCCACTTGCACA

'''

set_size = len(FOXP2)

def makeMaterial(name, diffuse, specular, alpha):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = diffuse
    mat.diffuse_shader = 'LAMBERT' 
    mat.diffuse_intensity = 1.0 
    mat.specular_color = specular
    mat.specular_shader = 'COOKTORR'
    mat.specular_intensity = 0.5
    mat.alpha = alpha
    mat.ambient = 1
    return mat

def setMaterial(ob, mat):
    me = ob.data
    me.materials.append(mat)

    # Create four materials
red = makeMaterial('Red', (1,0,0), (0,0,0), .5)
blue = makeMaterial('BlueSemi', (0,0,1), (0,0,0), 0.5)
green = makeMaterial('Green',(0,1,0), (0,0,0), 0.5)
yellow = makeMaterial('Yellow',(1,1,0), (0,0,0), 0.5)
black = makeMaterial('Black',(0,0,0), (0,0,0), 0.5)
white = makeMaterial('White',(1,1,1), (0,0,0), 0.5)    

def make_sphere(volume, position):
    create = bpy.ops.mesh.primitive_uv_sphere_add
    create(size=volume, location=position)


    # Builds a list of coordinate points
radius = 11
deltas = [[1,0,-1],[0,1,-1],[-1,1,0],[-1,0,1],[0,-1,1],[1,-1,0]]
hex_coords = []
for r in range(radius):
    x = 0
    y = -r
    z = +r
    points = x,y,z
    hex_coords.append(points)
    for j in range(6):
        if j==5:
            num_of_hexas_in_edge = r-1
        else:
            num_of_hexas_in_edge = r
        for i in range(num_of_hexas_in_edge):
            x = x+deltas[j][0]
            y = y+deltas[j][1]
            z = z+deltas[j][2] 
            plot = x,y,z           
            hex_coords.append(plot)   

    # Color-codes sequence and appends to color_array

color_array = []

for x in FOXP2:
    if x == 'A':
        color_array.append(1)
    elif x == 'T':
        color_array.append(1)
    elif x == 'C':
        color_array.append(0)
    elif x == 'G':
        color_array.append(0)
    else:
        pass

    # Pulls from sequence data and applies color to sphere
    # Positions sphere to coordinates     
    # Pulls from color_code and applies color scheme to sphere object 

for x in color_array: 
    if x =='RED':
        coord_tuple = hex_coords.pop(0) 
        make_sphere(1, coord_tuple)
        setMaterial(bpy.context.object, red)

    elif x =='GREEN':
        coord_tuple = hex_coords.pop(0)
        make_sphere(1, coord_tuple)
        setMaterial(bpy.context.object, green)

    elif x =='BLUE':
        coord_tuple = hex_coords.pop(0)
        make_sphere(1, coord_tuple)
        setMaterial(bpy.context.object, blue)

    elif x =='YELLOW':
        coord_tuple = hex_coords.pop(0)
        make_sphere(1, coord_tuple)
        setMaterial(bpy.context.object, yellow)

    else:
        pass
4

0 回答 0