point 球体 xyz 軸 11個 グラデーション
import bpy
def create_sphere_at_position(position, color, name):
# 半径を設定
radius = 0.1
# 球を作成(指定した座標に)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=position)
sphere = bpy.context.active_object
# マテリアルを作成
material = bpy.data.materials.new(name="Material_" + name)
sphere.data.materials.append(material)
# マテリアルの設定
material.use_nodes = False
material.diffuse_color = color
# オブジェクトの名前を設定
sphere.name = name
# 色の範囲を設定
x_start_color = (0.8, 0.2, 0.2, 1.0) # もっと濃い赤 (R:0.8, G:0.2, B:0.2, A:1.0)
x_end_color = (1.0, 0.5, 0.5, 1.0) # 赤 (R:1.0, G:0.5, B:0.5, A:1.0)
y_start_color = (0.2, 0.8, 0.2, 1.0) # もっと濃い緑 (R:0.2, G:0.8, B:0.2, A:1.0)
y_end_color = (0.5, 1.0, 0.5, 1.0) # 緑 (R:0.5, G:1.0, B:0.5, A:1.0)
z_start_color = (0.2, 0.2, 0.8, 1.0) # もっと濃い青 (R:0.2, G:0.2, B:0.8, A:1.0)
z_end_color = (0.5, 0.5, 1.0, 1.0) # 青 (R:0.5, G:0.5, B:1.0, A:1.0)
# それぞれの軸用にコレクションを作成
x_collection = bpy.data.collections.new("points_x軸")
bpy.context.scene.collection.children.link(x_collection)
y_collection = bpy.data.collections.new("points_y軸")
bpy.context.scene.collection.children.link(y_collection)
z_collection = bpy.data.collections.new("points_z軸")
bpy.context.scene.collection.children.link(z_collection)
# 各軸の色変化の方向を設定(0: 順方向, 1: 逆方向)
x_direction = 0 # x軸を順方向とする
y_direction = 0 # y軸を順方向とする
z_direction = 0 # z軸を順方向とする
# 11個の球体を均等に配置
for i in range(-5, 6):
x_position = i
y_position = i
z_position = i
# x軸の色の変化を計算(順方向に設定)
x_t = i / 10.0 if x_direction == 0 else (10 - i) / 10.0
x_color = [
x_start_color[0] * (1 - x_t) + x_end_color[0] * x_t,
x_start_color[1] * (1 - x_t) + x_end_color[1] * x_t,
x_start_color[2] * (1 - x_t) + x_end_color[2] * x_t,
1.0,
]
# y軸の色の変化を計算(順方向に設定)
y_t = i / 10.0 if y_direction == 0 else (10 - i) / 10.0
y_color = [
y_start_color[0] * (1 - y_t) + y_end_color[0] * y_t,
y_start_color[1] * (1 - y_t) + y_end_color[1] * y_t,
y_start_color[2] * (1 - y_t) + y_end_color[2] * y_t,
1.0,
]
# z軸の色の変化を計算(順方向に設定)
z_t = i / 10.0 if z_direction == 0 else (10 - i) / 10.0
z_color = [
z_start_color[0] * (1 - z_t) + z_end_color[0] * z_t,
z_start_color[1] * (1 - z_t) + z_end_color[1] * z_t,
z_start_color[2] * (1 - z_t) + z_end_color[2] * z_t,
1.0,
]
create_sphere_at_position((x_position, 0, 0), x_color, f"x_point({x_position}, 0, 0)")
create_sphere_at_position((0, y_position, 0), y_color, f"y_point(0, {y_position}, 0)")
create_sphere_at_position((0, 0, z_position), z_color, f"z_point(0, 0, {z_position})")
mokuji000zionad.hatenablog.com