Last active
April 1, 2021 16:40
-
-
Save jkrumbiegel/ba1335b2d45b77171322bd595d7c2f3e to your computer and use it in GitHub Desktop.
Live GLMakie Monte Carlo pi animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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