2023年4月25日火曜日

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





# ランダム配置 球体表面に36個 球体



import bpy

import math

import random


# 大きい球体の情報

zion_big_sphere_name = "Center Sphere"  # 大きい球体の名前

zion_big_sphere_radius = 2.0  # 大きい球体の半径

zion_big_sphere_location = (0, 0, 0)  # 大きい球体の位置

zion_big_sphere_rotation_speed = 600  # 1回転するのに要するフレーム数

zion_big_sphere_rotation_direction = 1  # 回転方向(1: 反時計回り、-1: 時計回り)


# 小さい球体の情報

zion_small_sphere_name = "Small Sphere"  # 小さい球体の名前

zion_small_sphere_count = 36  # 小さい球体の数

zion_small_sphere_radius = 0.1  # 小さい球体の半径


# 大きい球体を作成

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


# 大きい球体を変数に格納

zion_big_sphere = bpy.context.object

zion_big_sphere.name = zion_big_sphere_name


# 小さい球体を作成

for i in range(zion_small_sphere_count):

    # 球面座標を計算

    theta = random.uniform(0, 2 * math.pi)

    phi = random.uniform(0, math.pi)

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

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

    z = zion_big_sphere_radius * math.cos(phi)

    location = (x, y, z)


    # 小さい球体を作成

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


    # 小さい球体を大きい球体の子オブジェクトにする

    zion_small_sphere = bpy.context.object

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

    zion_small_sphere.parent = zion_big_sphere


# アニメーションを作成

frame_count = zion_big_sphere_rotation_speed

for i in range(frame_count):

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

    zion_big_sphere.rotation_euler.rotate_axis("Z", zion_big_sphere_rotation_direction * 2 * math.pi / frame_count)


    # 小さい球体を大きい球体の表面に沿って移動させる

    for j in range(zion_small_sphere_count):

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

        small_sphere = bpy.data.objects[small_sphere_name]

        sphere_phi = math.acos(small_sphere.location[2] / zion_big_sphere_radius)

        sphere_theta = math.atan2(small_sphere.location[1], small_sphere.location[0]) + zion




2023年4月24日月曜日

20230425 tue 球体表面 回転

 




import bpy

from math import radians


# 定義:数値調整

zion_radius = 2.0

zion_center_spher = (0, 0, 0)

zion_kaiten_frame = 300

zion_name = "表面回転球体"


# 球体を作成

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


# オブジェクト名を変更

bpy.context.object.name = zion_name


# 回転アニメーションを設定

bpy.context.scene.frame_end = zion_kaiten_frame


rotation_degrees = 360.0 / zion_kaiten_frame


for i in range(zion_kaiten_frame):

    bpy.context.scene.frame_set(i)

    bpy.context.object.rotation_euler[2] = radians(rotation_degrees * i)

    bpy.ops.anim.keyframe_insert(type='Rotation')
















blender pythonで スクリプト書く

定義 数値調整は スクリプトの先頭に書く


オブジェクト名は

zion_name " 表面 回転球体"


球体を作成

球体半径 zion_radius = 2.0

球体 中心位置 zion_center_spher = (0,0,0)


球体を回転させる

frame 300 で 1回転

zion_kaiten_frame =300




半径2の

2023年4月22日土曜日

20230423 sun 球体 複数と 光行差

 







blendr python で


半径0.2 の球体を作成

オブジェクト名は zion_ball = "x_ball"


球体中心は (x,0,0)


xは ー10から+10の21位置


描いて



import bpy

import mathutils


# 半径0.2の球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.2)


# オブジェクト名を設定

bpy.context.object.name = "x_ball"


# 球体を各x座標に配置

for x in range(-10, 11):

    # 球体を複製して新しいオブジェクトを作成

    bpy.ops.object.duplicate(linked=False)

    new_obj = bpy.context.object

    

    # 新しいオブジェクトのオブジェクト名を設定

    new_obj.name = "x_ball_{0}".format(x)

    

    # 新しいオブジェクトを移動するベクトルを作成

    translate_vec = mathutils.Vector((x, 0, 0))

    

    # 新しいオブジェクトを移動

    new_obj.location = translate_vec




20230422 bbb 半径2に修正

 




https://polyhaven.com/a/sandsloot



#あああああああああああああああああああああ 


import bpy


# カメラの位置を変更する

bpy.data.objects['Camera'].location = (0, 10, 0)


# ライトの位置を変更する

bpy.data.objects['Light'].location = (0, 10, 1)




#あああああああああああああああああああああ 






20230422 sat ビデオ会議の構造 test版 半径√3へ 修正へ

 


blender python で

半径1の球体を 作る

中心は000


y<0の部分と

y>=0の部分に別ける


2つの部分にオブジェクト名を付ける




Y>=0 の 半分の球体と Y<=0 の 半分の球体を描いて オブジェクト名も付ける





import bpy

import bmesh

import mathutils

import math


# Y>=0 の半分の球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0.5), radius=0.5, segments=32, ring_count=16)

half_sphere_top = bpy.context.active_object

half_sphere_top.name = "Half Sphere Top"


# Y<=0 の半分の球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, -0.5), radius=0.5, segments=32, ring_count=16)

half_sphere_bottom = bpy.context.active_object

half_sphere_bottom.name = "Half Sphere Bottom"


# 2つのオブジェクトを結合する

bpy.context.view_layer.objects.active = half_sphere_bottom

bpy.ops.object.mode_set(mode='EDIT')

bm = bmesh.from_edit_mesh(bpy.context.object.data)

bm.select_mode = {'VERTEX'}

bm.select_flush(mode='VERT')

bm.select_all(action='SELECT')

bpy.ops.mesh.delete(type='VERT')

bpy.ops.object.mode_set(mode='OBJECT')


bpy.ops.object.select_all(action='DESELECT')

half_sphere_top.select_set(True)

half_sphere_bottom.select_set(True)

bpy.context.view_layer.objects.active = half_sphere_top

bpy.ops.object.join()


# オブジェクトを選択する

bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]





2023年4月20日木曜日

20230421 fri

 



【神アプデ】GoodNotes 5の進化が止まらない…!

https://www.youtube.com/watch?v=pBbBLcTEfTE


20230420 thu 球体60個を 過去光円錐 底面円周から 動かす

 




# トーラス 完全版 過去光円錐

import bpy

import math


# Adjust movement speed

torus_speed = 0.01


# Parameters

radius = 1


# Create a torus

bpy.ops.mesh.primitive_torus_add(align='WORLD', location=(0, 0, -2), rotation=(0, 0, 0), major_radius=radius, minor_radius=0.05)

torus = bpy.context.active_object


# Set the animation for the torus

for i in range(601):

    # Set the current frame

    bpy.context.scene.frame_set(i)


    # Move the torus

    loc = (0, 0, -2 + i * torus_speed)

    torus.location = loc


    # Resize the torus

    radius = abs(loc[2])

    torus.scale = (radius, radius, radius)


    # Add a keyframe

    torus.keyframe_insert(data_path="location")

    torus.keyframe_insert(data_path="scale")









import bpy

import math

import mathutils


# パラメーター

radius = 2

num_spheres = 60

sphere_radius = 0.1

z = -2


# 円周上に球体を配置

for i in range(num_spheres):

    angle = 2 * math.pi * i / num_spheres

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    

    # 球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))








import bpy
import math
import mathutils

# パラメーター
radius = 2
num_spheres = 30
sphere_radius = 0.1
z = -2

# 円周上に球体を配置
for i in range(num_spheres):
    angle = 2 * math.pi * i / num_spheres
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)
    
    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))
    
    # オブジェクトを取得
    obj = bpy.context.object
    
    # アニメーションを作成
    obj.location = (0, 0, 0)
    obj.keyframe_insert(data_path="location", frame=1)
    obj.location = (x, y, z)
    obj.keyframe_insert(data_path="location", frame=250)

# タイムラインを調整して、アニメーションを再生する
bpy.context.scene.frame_end = 250
bpy.context.scene.render.fps = 30
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.ops.render.render(animation=True, write_still=True)




蛇になった




import bpy

import math

import mathutils


# パラメーター

radius = 2

num_spheres = 30

sphere_radius = 0.1

z = -2


# 円周上に球体を配置

for i in range(num_spheres):

    angle = 2 * math.pi * i / num_spheres

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)


    # 球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))


    # オブジェクトを取得

    obj = bpy.context.object


    # アニメーションを作成

    obj.location = (x, y, z)

    obj.keyframe_insert(data_path="location", frame=i * 3 + 1)

    obj.location = (0, 0, 0)

    obj.keyframe_insert(data_path="location", frame=i * 3 + 61)


# トーラスを描画する関数

def create_torus(location, radius):

    bpy.ops.mesh.primitive_torus_add(align='WORLD', location=location, rotation=(0, 0, 0), major_radius=radius, minor_radius=0.05)


# トーラスを描画

create_torus((0, 0, -2), 2)


# アニメーションの設定

for i in range(101):

    # 現在のフレームをセット

    bpy.context.scene.frame_set(i)


    # トーラスの座標を変更

    loc = (0, 0, -2 + i * 0.07)

    bpy.data.objects["Torus"].location = loc


    # トーラスのサイズを変更

    radius = abs(loc[2])

    bpy.data.objects["Torus"].scale = (radius, radius, radius)


    # キーフレームを追加

    bpy.data.objects["Torus"].keyframe_insert(data_path="location")

    bpy.data.objects["Torus"].keyframe_insert(data_path="scale")


# タイムラインを調整して、アニメーションを再生する

bpy.context.scene.frame_end = 303

bpy.context.scene.render.fps = 30

bpy.context.scene.render.image_settings.file_format = 'PNG'

bpy.ops.render.render(animation=True, write_still=True)



















あああああああああああああああああああああああああああ


これも 蛇


import bpy
import math

# パラメーター
radius = 2
num_spheres = 30
sphere_radius = 0.1
z = -2

# 円周上に球体を配置
for i in range(num_spheres):
    angle = 2 * math.pi * i / num_spheres
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)

    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))

    # オブジェクトを取得
    obj = bpy.context.object

    # アニメーションを作成
    obj.location = (x, y, z)
    obj.keyframe_insert(data_path="location", frame=i * 3 + 1)
    obj.location = (0, 0, 0)
    obj.keyframe_insert(data_path="location", frame=i * 3 + 61)

    # 0に到達した球体を削除
    if i == num_spheres-1:
        bpy.ops.object.delete()

# 最初の球体と同じ位置に球体を発生させる
prev_loc = (radius, 0, z)
prev_frame = num_spheres * 3 + 61
for i in range(num_spheres-1):
    loc = (radius * math.cos(angle), radius * math.sin(angle), z)
    angle += 2 * math.pi / num_spheres

    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=loc)

    # オブジェクトを取得
    obj = bpy.context.object

    # アニメーションを作成
    obj.location = prev_loc
    obj.keyframe_insert(data_path="location", frame=prev_frame)
    obj.location = loc
    obj.keyframe_insert(data_path="location", frame=prev_frame+60)

    # 前の位置を更新
    prev_loc = loc
    prev_frame += 60

# トーラスを描画する関数
def create_torus(location, radius):
    bpy.ops.mesh.primitive_torus_add(align='WORLD', location=location, rotation=(0, 0, 0), major_radius=radius, minor_radius=0.05)

# トーラスを描画
create_torus((0, 0, -2), 2)

# アニメーションの設定
for i in range(202):
    # 現在のフレームをセット
    bpy.context.scene.frame_set(i)

    # トーラスの座標を変更
    loc = (0, 0, -2 + i * 0.035)
    bpy.data.objects["Torus"].location = loc

   







import bpy
import math
import mathutils

# 移動速度の調整
zion_speed = 0.2

# パラメーター
radius = 2
num_spheres = 30
sphere_radius = 0.1
z = -2

# 円周上に球体を配置
for i in range(num_spheres):
    angle = 2 * math.pi * i / num_spheres
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)
    
    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))
    
    # オブジェクトを取得
    obj = bpy.context.object
    
    # アニメーションを作成
    obj.location = (x, y, z)
    obj.keyframe_insert(data_path="location", frame=i * 3 / zion_speed + 1)
    obj.location = (0, 0, 0)
    obj.keyframe_insert(data_path="location", frame=i * 3 / zion_speed + 61)




# 最初の球体を再度出発させる
obj = bpy.context.selected_objects[0]
obj.location = (radius, 0, z)
obj.keyframe_insert(data_path="location", frame=num_spheres * 3 / zion_speed + 1)
obj.location = (0, 0, 0)
obj.keyframe_insert(data_path="location", frame=num_spheres * 3 / zion_speed + 61)




再度 球体を動かす




import bpy
import math

# Adjust movement speed
torus_speed = 0.02
sphere_speed = 0.2

# Parameters
radius = 2
num_spheres = 30
sphere_radius = 0.1
z = -2

# Place spheres on a circular path
for i in range(num_spheres):
    angle = 2 * math.pi * i / num_spheres
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)
    
    # Create sphere
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, enter_editmode=False, location=(x, y, z))
    
    # Get object
    obj = bpy.context.object
    obj.name = f"Sphere{i+1}"
    
    # Set animation
    obj.location = (x, y, z)
    obj.keyframe_insert(data_path="location", frame=i * 3 / sphere_speed + 1)
    obj.location = (0, 0, 0)
    obj.keyframe_insert(data_path="location", frame=i * 3 / sphere_speed + 61)

# Function to create torus
def create_torus(location, radius):
    bpy.ops.mesh.primitive_torus_add(align='WORLD', location=location, rotation=(0, 0, 0), major_radius=radius, minor_radius=0.05)
    obj = bpy.context.object
    obj.name = "Torus"
    return obj

# Create torus
torus = create_torus((0, 0, -2), 2)

# Set animation
for i in range(101):
    # Set current frame
    bpy.context.scene.frame_set(i)

    # Move torus
    loc = (0, 0, -2 + i * torus_speed)
    torus.location = loc

    # Resize torus
    radius = abs(loc[2])
    torus.scale = (radius, radius, radius)

    # Add keyframe
    torus.keyframe_insert(data_path="location")
    torus.keyframe_insert(data_path="scale")

# Restart first sphere when all 30 spheres have left
bpy.context.scene.frame_set(num_spheres * 3 / sphere_speed + 61)
bpy.context.scene.frame_current = num_spheres * 3 / sphere_speed + 1
for i in range(1, num_spheres+1):
    bpy.data.objects[f"Sphere{i}"].keyframe_insert(data_path="location", frame=num_spheres * 3 / sphere_speed + 1)