2023年4月8日土曜日

20230409 sun # Z軸 分布 球体 原型


# Z軸 分布 球体


import bpy

from mathutils import Vector


# 球体の中心位置リストを作成する

centers = []

for i in range(5):

    z = -30 + i*15

    centers.append(Vector((0, 0, z)))


# 目標位置を指定する

target_location = Vector((-30, 0, 0))


# フレーム数を指定する

last_frame = 600


# 移動する距離を指定する

distance_per_frame = 0.1


# スフィアの作成

for center in centers:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=center)


# アニメーションの作成

for frame in range(last_frame+1):

    for index, obj in enumerate(bpy.data.objects):

        if obj.name.startswith("Sphere"):

            distance = (target_location - obj.location).length

            if distance > 0.01:  # 目標位置にまだ到達していない場合

                direction = (target_location - obj.location).normalized()

                obj.location += direction * min(distance_per_frame, distance)

                obj.keyframe_insert(data_path="location", frame=frame)





# x軸 分布 数直線 時計


import bpy

from mathutils import Vector


# 球体の中心位置リストを作成する

centers = []

for i in range(21):

    x = 0 + i*10

    centers.append(Vector((x, 0, 0)))


# 目標位置を指定する

target_location = Vector((-30, 0, 0))


# フレーム数を指定する

last_frame = 600


# 移動する距離を指定する

distance_per_frame = 0.1


# スフィアの作成

for center in centers:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=center)


# アニメーションの作成

for frame in range(last_frame+1):

    for index, obj in enumerate(bpy.data.objects):

        if obj.name.startswith("Sphere"):

            distance = (target_location - obj.location).length

            if distance > 0.01:  # 目標位置にまだ到達していない場合

                direction = (target_location - obj.location).normalized()

                obj.location += direction * min(distance_per_frame, distance)

                obj.keyframe_insert(data_path="location", frame=frame)








import bpy

# フレーム数を変更するための関数
def set_frame_range(start_frame, end_frame):
    bpy.context.scene.frame_start = start_frame
    bpy.context.scene.frame_end = end_frame

# メイン関数
def main():
    # フレームレンジを設定する
    set_frame_range(1, 640)

# スクリプトを実行する
if __name__ == "__main__":
    main()




改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...