2023年4月6日木曜日

合体円錐 16個? 上昇

 


import bpy

import math

from mathutils import Vector


# 円錐のパラメーター

radius = 60

height = 60

num_points = 16


# 移動する距離

distance_per_frame = 0.05


# 球体のリストを作成する

cones = []

for i in range(num_points):

    # 角度を計算する

    angle = i * 2 * math.pi / num_points

    # x, y座標を計算する

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    # 頂点の位置を設定する

    vertex = (x, y, 0)

    # 円錐を作成する

    bpy.ops.mesh.primitive_cone_add(

        radius1=0, 

        radius2=radius, 

        depth=height, 

        location=vertex,

        rotation=(0, 0, 0)

    )

    cone = bpy.context.active_object

    # 円錐の名前を設定する

    cone.name = "Cone_{}".format(i)

    cones.append(cone)


# フレーム数の初期化

frame_num = 0


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

def animate_cones(scene):

    global frame_num

    # 球体を回転させる

    for i, cone in enumerate(cones):

        # 角度を計算する

        angle = i * 2 * math.pi / num_points + frame_num * 0.1

        # x, y座標を計算する

        x = radius * math.cos(angle)

        y = radius * math.sin(angle)

        # 頂点の位置を設定する

        vertex = (x, y, frame_num * distance_per_frame)

        # 円錐を移動する

        cone.location = vertex

        # 円錐を回転させる

        cone.rotation_euler[2] += 0.1

    # フレーム数を1増やす

    frame_num += 1


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

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


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

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