2023年4月5日水曜日

16個 動く



#16 個 回転


import bpy

import math

from mathutils import Vector


zion_speed_round = 0.1 # 回転速度を設定する

radius = 60 # 半径を設定する

distance_per_frame = 0.2 # 移動する距離を指定する


# 16個の球体を作成する

spheres = []

for i in range(16):

    angle = 2 * i * math.pi / 16

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = -60

    location = Vector((x, y, z))

    sphere_radius = 1

    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=sphere_radius)

    obj = bpy.context.active_object

    obj.name = "Sphere_" + str(i)  # オブジェクトに名前を付ける

    spheres.append(obj)


# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# 毎フレーム呼び出される関数

def animate_spheres(scene):

    global frame_num

    for i, sphere in enumerate(spheres):

        # 現在のフレーム数から球体の角度を計算する

        angle = 2 * i * math.pi / 16 + frame_num * zion_speed_round

        x = radius * math.cos(angle)

        y = radius * math.sin(angle)

        z = 0

        location = Vector((x, y, z))

        # 球体の位置を更新する

        sphere.location = location

        # 球体を回転する

        sphere.rotation_euler[2] += zion_speed_round

    # フレーム数を1増やす

    frame_num += 1


# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_spheres)









#16 個 Reverse 回転



import bpy
import math
from mathutils import Vector

zion_speed_round = -0.1 # 回転速度を設定する
radius = 60 # 半径を設定する
distance_per_frame = 0.2 # 移動する距離を指定する

# 16個の球体を作成する
spheres = []
for i in range(16):
    angle = 2 * i * math.pi / 16
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)
    z = -60

    location = Vector((x, y, z))

    sphere_radius = 1

    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=sphere_radius)
    obj = bpy.context.active_object
    obj.name = "Sphere_" + str(i)  # オブジェクトに名前を付ける
    spheres.append(obj)



# 時間を表すフレーム数の初期値を設定する

frame_num = 0



# 毎フレーム呼び出される関数

def animate_spheres(scene):

    global frame_num

    for i, sphere in enumerate(spheres):

        # 現在のフレーム数から球体の角度を計算する

        angle = 2 * i * math.pi / 16 + frame_num * zion_speed_round

        x = radius * math.cos(angle)

        y = radius * math.sin(angle)

        z = 0

        location = Vector((x, y, z))

        # 球体の位置を更新する

        sphere.location = location

        # 球体を回転する

        sphere.rotation_euler[2] += zion_speed_round

    # フレーム数を1増やす

    frame_num += 1



# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_spheres)








import bpy

import math

from mathutils import Vector



zion_speed_round = 1.0 # 回転速度を設定する

radius = 30 # 半径を設定する

distance_per_frame = 0.2 # 移動する距離を指定する


# 16個の球体を作成する

spheres = []

for i in range(16):

    angle = 2 * i * math.pi / 16

    x = 30 * math.cos(angle)

    y = 30 * math.sin(angle)

    z = 0

    location = Vector((x, y, z))

    radius = 1

    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)

    obj = bpy.context.active_object

    obj.name = "Sphere_" + str(i)  # オブジェクトに名前を付ける

    spheres.append(obj)


# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# 毎フレーム呼び出される関数

def animate_spheres(scene):

    global frame_num

    for i, sphere in enumerate(spheres):

        # 現在のフレーム数から球体の角度を計算する

        angle = 2 * i * math.pi / 16 + frame_num * 0.02

        x = 30 * math.cos(angle)

        y = 30 * math.sin(angle)

        z = 0

        location = Vector((x, y, z))

        # 球体の位置を更新する

        sphere.location = location

    # フレーム数を1増やす

    frame_num += 1


# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_spheres)




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

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