point 球体 半径 0.1 x軸 -5から+5 11個

point 球体 半径 0.1   x軸 -5から+5 11個

 

 



 

drive.google.com

 

 

 

 

# point 球体 半径 0.1   x軸 -5から+5 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

# 色の範囲を設定
start_color = (0.0, 0.0, 1.0, 1.0)  # 青の薄い色 (R:0.0, G:0.0, B:1.0, A:1.0)
end_color = (1.0, 0.0, 0.0, 1.0)    # 赤の薄い色 (R:1.0, G:0.0, B:0.0, A:1.0)

# 11個の球体を均等に配置
for i in range(-5, 6):
    x_position = i
    y_position = 0
    z_position = 0

    # 色の変化を計算
    t = (i + 5) / 10.0
    color = [
        (1 - t) * start_color[0] + t * end_color[0],
        (1 - t) * start_color[1] + t * end_color[1],
        (1 - t) * start_color[2] + t * end_color[2],
        1.0,
    ]

    name = f"point({x_position},{y_position},{z_position})"
    create_sphere_at_position((x_position, y_position, z_position), color, name)

 

 

 

 

 

 

 



 

青の薄い色から赤の薄い色への色の変化を計算して、

それに基づいて球体の色を設定しています。

 

start_colorは青の薄い色を示し、

end_colorは赤の薄い色を示します。

 

その後、forループ内でt(0から1の範囲)を計算して、

start_colorとend_colorの間でRGB値を

 

線形補間して色を求めています

 

 

 

 

import bpy

# List of collection names
collection_names = [
    "point球体",
    "points x軸",
    "points y軸",
    "points z軸",
]

# Function to create a new collection if it doesn't exist
def create_collection_if_not_exists(name):
    if name not in bpy.data.collections:
        collection = bpy.data.collections.new(name)
        bpy.context.scene.collection.children.link(collection)

# Create collections
for name in collection_names:
    create_collection_if_not_exists(name)

 

 

 

 

 

 

 

 

mokuji000zionad.hatenablog.com