# Corrected method to handle transparency and create a moving effect

# Initialize canvas size and transparency
canvas_size = (image.width, image.height)
background_color = (255, 255, 255, 255)  # White background

# Generate frames showing components moving into position
frames_movement = []

# Number of steps for the animation
steps = 10

# Define offsets for the start positions
start_positions = [(50, 50), (-50, -50), (50, -50), (-50, 50), (0, 0)]

# Loop through steps to create animation frames
for step in range(steps + 1):
    # Create a blank white frame
    frame = Image.new("RGBA", canvas_size, background_color)
    draw = ImageDraw.Draw(frame)
    
    # Simulate component movement by gradually reducing offsets
    for x_offset, y_offset in start_positions:
        current_x = int(x_offset * (1 - step / steps))
        current_y = int(y_offset * (1 - step / steps))
        # Paste interconnected image progressively into position
        frame.alpha_composite(image_interconnected, (current_x, current_y))
    
    # Add frame to the animation list
    frames_movement.append(frame)

# Save as GIF
gif_path_movement = "/mnt/data/components_moving_into_place_corrected.gif"
frames_movement[0].save(
    gif_path_movement,
    save_all=True,
    append_images=frames_movement[1:],
    duration=100,  # 100ms per frame
    loop=0  # Infinite loop
)

gif_path_movement
