机械荟萃山庄

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 426|回复: 0

ChatGPT用Python做的旋转动画代码

[复制链接]

143

主题

652

帖子

5490

积分

论坛元老

Rank: 8Rank: 8

积分
5490
发表于 2023-1-6 17:05:35 | 显示全部楼层 |阅读模式
本帖最后由 包作工 于 2023-1-6 17:15 编辑

ChatGPT用Python做的旋转动画代码。没有测试过。如下;

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np

# Set up the figure and axes
fig, ax = plt.subplots()

# Set up the parameters of the animation
num_frames = 360  # Number of frames in the animation
fps = 60          # Frame rate (frames per second)

# Create a function that returns the coordinates of the points to be plotted
def get_points(angle):
  x = np.cos(np.radians(angle))
  y = np.sin(np.radians(angle))
  return x, y

# Create the init function that sets up the plot
def init():
  ax.set_xlim(-1.5, 1.5)
  ax.set_ylim(-1.5, 1.5)
  line, = ax.plot([], [], "o-")  # Create the plot object
  return line,

# Create the update function that updates the plot for each frame
def update(i):
  x, y = get_points(i)  # Get the coordinates for the current frame
  line.set_data(x, y)   # Update the plot data
  return line,

# Create the animation object
anim = animation.FuncAnimation(
    fig, update, frames=num_frames, init_func=init, interval=1000/fps
)

# Show the animation
plt.show()

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

评分

参与人数 1威望 +3 收起 理由
Architect + 3

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|机械荟萃山庄 ( 辽ICP备16011317号-1 )

GMT+8, 2024-9-21 21:57 , Processed in 0.093233 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表