Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:01
Show Gist options
  • Save st98/ef65ea3aac15b8c7f5d2 to your computer and use it in GitHub Desktop.
Save st98/ef65ea3aac15b8c7f5d2 to your computer and use it in GitHub Desktop.
モンテカルロ法でうんぬん。
*init
screen 0, 256, 256
title "もんかる"
num = 0
n = 0
pos 72, 120
mes "クリックで開始"
onclick *main
stop
*main
cls
repeat
redraw 0
x = rnd(256)
y = rnd(256)
if (x * x + (256 - y) * (256 - y)) < 256 * 256 {
color 144, 144, 255
n += 1
} else {
color 255, 144, 144
}
boxf x - 2, y, x + 2, y
boxf x, y - 2, x, y + 2
num += 1
title "π ≒ " + (4.0 * n / num)
redraw 1
await 17
loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment