Skip to content

Instantly share code, notes, and snippets.

@empet
Created October 11, 2023 09:28
Show Gist options
  • Select an option

  • Save empet/c8839bfd3fde60a4d114ae2b8fd8d89f to your computer and use it in GitHub Desktop.

Select an option

Save empet/c8839bfd3fde60a4d114ae2b8fd8d89f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "ccebeda0",
"metadata": {},
"outputs": [],
"source": [
"using PlotlyJS\n",
"import Plots: Animation, buildanimation\n",
"let\n",
" \n",
"f(x,y, phi) = 60*cos(2*atan(y/(x+0.00001)) + 0.544331*sqrt(x^2+y^2)-phi) / (20+sqrt(x^2+y^2));\n",
"\n",
"x = y = range(-45, 45, length=200)\n",
"X = [y for x in x, y in y]\n",
"Y = [x for x in x, y in y] # X, Y are used to evaluate f.(X,Y, phi[k]) for each frame, k\n",
"\n",
"fig = Plot([scatter3d(x=[-46, 46], y=[-46, 46], z=[-3,3], \n",
" mode=\"markers\", marker_size=0.1), \n",
" surface(x=x, y=y, z = f.(X, Y, 0), \n",
" colorscale=colors.ice, showscale=false)],\n",
" Layout(width=500, height=500, font_size=11, \n",
" scene=attr(aspectmode=\"data\", \n",
" zaxis_range=[-3,3],\n",
" camera_eye=attr(x=2.65, y=2.65, z=1.25)), #perspect. proj is the default proj\n",
" margin=attr(t=2, r=2, b=2, l=5))) #set small margins (white backgtound around the image) \n",
"\n",
"n_frames = 36\n",
"phi = range(0, 2*pi, n_frames)\n",
"fnames = String[]\n",
"for k in 1:n_frames\n",
" restyle!(fig, [2], z=[f.(X,Y, phi[k])])\n",
" filename=lpad(k, 6, \"0\")*\".png\"\n",
" push!(fnames, filename) \n",
" savefig(fig, \"images/\"*filename, width=500, height=500, scale=1)\n",
"end \n",
"\n",
"anim = Animation(\"images\", fnames);\n",
"buildanimation(anim, \"gravitational-waves.gif\", fps = 18, show_msg=false)\n",
" \n",
"end"
]
},
{
"cell_type": "markdown",
"id": "2f738cff",
"metadata": {},
"source": [
"%%html\n",
"<img src=\"https://github.com/empet/Datasets/blob/master/Images/gravitational-waves.gif?raw=true\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88d92508",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.9.0",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment