Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Last active March 5, 2022 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terasakisatoshi/8b1900d6ec642b5546925db57e1cd5d6 to your computer and use it in GitHub Desktop.
Save terasakisatoshi/8b1900d6ec642b5546925db57e1cd5d6 to your computer and use it in GitHub Desktop.
お星様 matplotlib animation
# Jupyter Notebook で実行してください
# https://qiita.com/yoku_/items/11ac4ad1df349095655c の Python 実装が
# https://gist.github.com/genkuroki/f1480db0c035d4cb82d1d5ec6989b05d?short_path=c1a52fb
# によって Julia によって移植され, 下記の実装は Julia 1.7 版です.
using PyPlot
using PyCall
anim = pyimport("matplotlib.animation")
t = range(0, stop=6π, length=60)
x = @. 2cos(t) + 5cos(2/3 * t)
y = @. 2sin(t) - 5sin(2/3 * t)
fig = figure(figsize=(5,5))
init() = (grid(ls=":"); xlim(-7.5, 7.5); ylim(-7.5, 7.5))
animate(i) =(clf(); init(); plot(x[1:i], y[1:i]))
ani = anim.FuncAnimation(fig, animate, frames=1:length(t), interval=1000/30)
@time ani_html = ani.to_jshtml()
clf()
sleep(0.1)
display("text/html", ani_html)
@terasakisatoshi
Copy link
Author

out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment