import bpy
import math
from mathutils import Vector
# Set target location
target_location = Vector((0, 0, 60))
# Set initial location and radius
initial_location = Vector((0, 0, 0))
sphere_radius = 2
# Create sphere object
bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=initial_location)
sphere = bpy.context.object
# Set animation keyframes
start_frame = 1
end_frame = 600
for frame in range(start_frame, end_frame+1):
# Calculate angle based on current frame
angle = (frame - start_frame) * 2 * math.pi / 200
# Calculate new sphere location
x = target_location.x + sphere_radius * math.cos(angle)
y = target_location.y + sphere_radius * math.sin(angle)
z = target_location.z
sphere.location = Vector((x, y, z))
# Set rotation
sphere.rotation_euler[2] = angle
# Insert keyframe
sphere.keyframe_insert(data_path="location", frame=frame)
sphere.keyframe_insert(data_path="rotation_euler", frame=frame)
# Set the number of frames
bpy.context.scene.frame_start = start_frame
bpy.context.scene.frame_end = end_frame