Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Last active April 1, 2021 16:40
Show Gist options
  • Save jkrumbiegel/ba1335b2d45b77171322bd595d7c2f3e to your computer and use it in GitHub Desktop.
Save jkrumbiegel/ba1335b2d45b77171322bd595d7c2f3e to your computer and use it in GitHub Desktop.
Live GLMakie Monte Carlo pi animation
using GLMakie
f = Figure(resolution = (1000, 1000))
ax = Axis(f[1, 1], aspect = 1, limits = (-1, 1, -1, 1))
points = Node(Point2f0[])
colors = Node(Bool[])
function draw!()
p = rand(Point2f0) .* 2 .- 1
c = sqrt(p[1] ^ 2 + p[2] ^ 2) <= 1
push!(points[], p)
push!(colors[], c)
end
sc = scatter!(points, color = colors, colormap = [:red, :blue],
markersize = 2, strokewidth = 0)
display(f)
for i in 1:100
for i in 1:10000
draw!()
end
notify(points)
notify(colors)
sleep(1/30)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment