Skip to content

Instantly share code, notes, and snippets.

@abap34
Created January 4, 2021 13:31
Show Gist options
  • Save abap34/5cca7c1b4bd93ec37c4c199befca2103 to your computer and use it in GitHub Desktop.
Save abap34/5cca7c1b4bd93ec37c4c199befca2103 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Plots\n",
"using PlotThemes\n",
"theme(:juno)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"using StatsBase:sample\n",
"using ProgressBars"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N = 1000\n",
"n_people = 4"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100.0%┣███████████████████████████████████████┫ 999/999 [00:45<00:00, 22.3 it/s]┣██████████████████████████████ ┫ 752/999 [00:31<00:10, 24.4 it/s]\n"
]
}
],
"source": [
"anim = Animation()\n",
"prev = zeros(Int, (N, n_people))\n",
"for i in ProgressBar(2:N)\n",
" prev[i, :] .= prev[i - 1, :] .+ sample([-1, 1], n_people)\n",
" plt = plot(prev)\n",
" frame(anim, plt)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"┌ Info: Saved animation to \n",
"│ fn = /Users/yuchi_ymgc/Desktop/_workspace/random_walker/randwalk.gif\n",
"└ @ Plots /Users/yuchi_ymgc/.julia/packages/Plots/8GUYs/src/animation.jl:102\n"
]
},
{
"data": {
"text/html": [
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment