2023年4月25日火曜日

20230426bbb 球体表面に 36個の球体 

 







import bpy

import math


# 大きい球体の半径

zion_big_sphere_radius = 6.0


# 小さい球体の半径

zion_small_sphere_radius = 0.1


# 大きい球体の回転数

frame_count = 600


# 小さい球体の数

zion_small_sphere_count = 360


# 小さい球体の名前

zion_small_sphere_name = "SmallSphere"


# 大きい球体の回転方向(時計回り)

zion_big_sphere_rotation_direction = -1


# 大きい球体を作成

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

zion_big_sphere = bpy.context.object

zion_big_sphere.name = "BigSphere"


# 小さい球体を作成

for i in range(zion_small_sphere_count):

    theta = i * math.pi / 180

    phi = i * math.pi / 180

    x = zion_big_sphere_radius * math.sin(theta) * math.cos(phi)

    y = zion_big_sphere_radius * math.sin(theta) * math.sin(phi)

    z = zion_big_sphere_radius * math.cos(theta) 


    bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_small_sphere_radius, location=(x, y, z))

    small_sphere = bpy.context.object

    small_sphere.name = zion_small_sphere_name + "." + str(i)


# アニメーションのキーフレームを生成する

for i in range(frame_count):

    # 大きい球体を回転させる

    zion_big_sphere = bpy.data.objects.get("BigSphere")

    if zion_big_sphere:

        zion_big_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

        zion_big_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


        # 小さい球体も同じ回転を加える

        for j in range(zion_small_sphere_count):

            small_sphere_name = zion_small_sphere_name + "." + str(j)

            small_sphere = bpy.data.objects.get(small_sphere_name)

            if small_sphere:

                small_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

                small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


                # 小さい球体の回転速度を大きい球体に合わせる

                small_sphere.rotation_euler[2] -= j * 2 * math.pi / zion_small_sphere_count

                small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)









import bpy

import math

import random


# 大きい球体の半径

zion_big_sphere_radius = 2.0


# 大きい球体の回転数

zion_big_sphere_rotation_count = 5


# 大きい球体の回転方向(正回転:1, 逆回転:-1)

zion_big_sphere_rotation_direction = 1


# キーフレームの数

frame_count = 1000


# 小さい球体のオブジェクト名と個数を指定

zion_small_sphere_name = "SmallSphere"

zion_small_sphere_count = 36


# 大きい球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_big_sphere_radius, enter_editmode=False, align='WORLD', location=(0, 0, 0))

zion_big_sphere = bpy.context.object

zion_big_sphere.name = "BigSphere"


# 小さい球体をランダムに配置するための親オブジェクトを作成する

small_sphere_group = bpy.data.objects.new("SmallSphereGroup", None)

bpy.context.scene.collection.objects.link(small_sphere_group)


# 小さい球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, enter_editmode=False, align='WORLD', location=(0, 0, 0))

small_sphere = bpy.context.object

small_sphere.name = zion_small_sphere_name

small_sphere.parent = small_sphere_group


for i in range(zion_small_sphere_count - 1):

    new_small_sphere = small_sphere.copy()

    new_small_sphere_name = zion_small_sphere_name + "." + str(i + 1)

    new_small_sphere.name = new_small_sphere_name

    bpy.context.scene.collection.objects.link(new_small_sphere)



# アニメーションのキーフレームを生成する

for i in range(frame_count):

    # 大きい球体を回転させる

    zion_big_sphere = bpy.data.objects.get("BigSphere")

    if zion_big_sphere:

        zion_big_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

        zion_big_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


        # 小さい球体も同じ回転を加える

        for j in range(zion_small_sphere_count):

            small_sphere_name = zion_small_sphere_name + "." + str(j)

            small_sphere = bpy.data.objects.get(small_sphere_name)

            if small_sphere:

                small_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

                small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


    # 小さい球体をランダムに配置する

    for j in range(zion_small_sphere_count):

        small_sphere_name = zion_small_sphere_name + "." + str(j)

        small_sphere = bpy.data.objects.get(small_sphere_name)

        if small_sphere:

            small_sphere.location = (random.uniform(-10, 10), random.uniform(-10, 10), random.uniform(-10, 10))

            small_sphere.keyframe_insert(data_path="location", frame=i)


    # 線分の10区間に9つの小さい球体を配置する

    small_sphere_1 = bpy.data.objects.get(zion_small_sphere_name + ".0")

    small_sphere_2 = bpy.data.objects.get(zion_small_sphere_name + ".1")

    if small_sphere_1 and small_sphere_2:

        line_start = small_sphere_1.location

        line_end = small_sphere_2.location

        line_vector = line_end - line_start

        line_length = line_vector.length

        small_sphere_distance = line_length / 10

        small_sphere_direction = line_vector.normalized()


        for j in range(1, 10):

            small_sphere_name = zion_small_sphere_name + "." + str(j + 1)

            small_sphere = bpy.data.objects.get(small_sphere_name)

            if small_sphere:

                small_sphere.location = line_start + small_sphere_direction * small_sphere_distance * j

                small_sphere.keyframe_insert(data_path="location", frame=i)







import bpy

import math

import random


# 大きい球体の半径

zion_big_sphere_radius = 2.0


# 大きい球体の回転数

zion_big_sphere_rotation_count = 5


# 大きい球体の回転方向(正回転:1, 逆回転:-1)

zion_big_sphere_rotation_direction = 1


# キーフレームの数

frame_count = 100


# 小さい球体のオブジェクト名と個数を指定

zion_small_sphere_name = "SmallSphere"

zion_small_sphere_count = 36


# 大きい球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_big_sphere_radius, enter_editmode=False, align='WORLD', location=(0, 0, 0))

zion_big_sphere = bpy.context.object

zion_big_sphere.name = "BigSphere"


# 小さい球体をランダムに配置するための親オブジェクトを作成する

small_sphere_group = bpy.data.objects.new("SmallSphereGroup", None)

bpy.context.scene.collection.objects.link(small_sphere_group)


# 小さい球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, enter_editmode=False, align='WORLD', location=(0, 0, 0))

small_sphere = bpy.context.object

small_sphere.name = zion_small_sphere_name

small_sphere.parent = small_sphere_group


for i in range(zion_small_sphere_count - 1):

    new_small_sphere = small_sphere.copy()

    new_small_sphere_name = zion_small_sphere_name + "." + str(i + 1)

    new_small_sphere.name = new_small_sphere_name

    bpy.context.scene.collection.objects.link(new_small_sphere)


# アニメーションのキーフレームを生成する

for i in range(frame_count):

    # 大きい球体を回転させる

    zion_big_sphere = bpy.data.objects.get("BigSphere")

    if zion_big_sphere:

        zion_big_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

        zion_big_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


    # 小さい球体をランダムに配置する

    for j in range(zion_small_sphere_count):

        small_sphere_name = zion_small_sphere_name + "." + str(j)

        small_sphere = bpy.data.objects.get(small_sphere_name)

        if small_sphere:

            small_sphere.location = (random.uniform(-10, 10), random.uniform(-10, 10), random.uniform(-10, 10))

            small_sphere.keyframe_insert(data_path="location", frame=i)


    # 線分の10区間に9つの小さい球体を配置する

    small_sphere_1 = bpy.data.objects.get(zion_small_sphere_name + ".0")

    small_sphere_2 = bpy.data.objects.get(zion_small_sphere_name + ".1")

    if small_sphere_1 and small_sphere_2:

        line_start = small_sphere_1.location

        line_end = small_sphere_2.location

        line_vector = line_end