Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2d random walk animation
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Base64\ndisplayfile(mime, file; tag=\"img\") = open(file) do f\n display(\"text/html\", \"\"\"<$tag src=\"data:$mime;base64,$(base64encode(f))\">\"\"\")\nend\n\nusing Plots\ngr(size=(400, 400))",
"execution_count": 1,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 1,
"data": {
"text/plain": "Plots.GRBackend()"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "N = 10000\nl = 500\nX = cumsum(randn(2, N+l), dims=2)\n\nxlim, ylim = extrema(X[1,:]), extrema(X[2,:])\n@time anim = @animate for i in 1:N\n plot(X[1,i:i+l], X[2,i:i+l], xlim=xlim, ylim=ylim, legend=false)\nend\n\n@time gif(anim, \"randomwalk.gif\", fps=100)\ndisplayfile(\"image/gif\", \"randomwalk.gif\")",
"execution_count": 1,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "327.153878 seconds (3.07 G allocations: 78.493 GiB, 6.42% gc time)\n"
},
{
"data": {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.