2023年4月9日日曜日

電車列車から見える 円柱 複数も

光時計 たくさん



import bpy

import math


zion_collection_name = "光時計たくさん"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)



import bpy

import math

zion_collection_name = "土台"

# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)















import bpy

import math

from mathutils import Vector

from math import radians


zion_collection_name = "cylinder "


# Create the collection

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)


# Set target location

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


# Set initial locations

initial_locations = [ Vector((0, 0, 0))]


# Set cylinder properties

cylinder_radius = 1

cylinder_depth = 180


# Calculate speeds based on initial distances

chousei_kijyun = 600

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create cylinder objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_depth)

    cylinder = bpy.context.object

    cylinder.location = initial_location

    cylinder.name = "電柱l"


    # Rotate cylinder by 90 degrees around the y-axis

    cylinder.rotation_euler.rotate_axis('Y', radians(0))


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - cylinder.location).length

        if distance > 0.01:

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

            cylinder.location += direction * min(speeds[i], distance)

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


# Set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)








複数 早く

import bpy
import math
from mathutils import Vector
from math import radians

zion_collection_name = "光時計たくさんcylinders"

# Create the collection
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)

# Set target location
target_location = Vector((-600, 0, 0))

# Set cylinder properties
cylinder_radius = 1
cylinder_depth = 180

# Set the number of frames
def set_frame_range(start_frame, end_frame):
    bpy.context.scene.frame_start = start_frame
    bpy.context.scene.frame_end = end_frame

# Set initial x locations and intervals
initial_x = range(-90, 3001, 100)

# Create cylinder objects and set locations
for i, x in enumerate(initial_x):
    initial_location = Vector((x, 0, 0))
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_depth)
    cylinder = bpy.context.object
    cylinder.location = initial_location
    cylinder.name = f"cylinder_{x}"
    col.objects.link(cylinder)

    # Rotate cylinder by 90 degrees around the y-axis
    cylinder.rotation_euler.rotate_axis('Y', radians(0))

    # Calculate speeds based on initial distances
    chousei_kijyun = 1000
    distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in [initial_location]]
    speeds = [1.0 * (chousei_kijyun / distance) if distance > 0 else 0 for distance in distances]

    # Set animation keyframes
    last_frame = 1000
    for frame in range(last_frame+1):
        distance = (target_location - cylinder.location).length
        if distance > 0.01:
            direction = (target_location - cylinder.location).normalized()
            cylinder.location += direction * min(speeds[0], distance)
            cylinder.keyframe_insert(data_path="location", frame=frame)

# Example: set the number of frames to 1000
set_frame_range(1, 1000)



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

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