1
| fig point comment x y random inArc tries|
2
"Monte-Carlo PI approximation"
3
fig _ DrGeoSketch new scale: 400.
5
fig arcCenter: 0@0 from: 1@0 to: 0@1.
6
fig polygon: { 0@0. 0@1. 1@1. 1@0 }.
7
comment _ fig text: '' at: 0@ -0.1.
8
random _ Random seed: Time millisecondClockValue.
11
1 to: tries do: [: try |
14
point _ (fig point: x@y) small.
15
(x squared + y squared) > 1
16
ifTrue: [point color: Color blue ]
17
ifFalse: [inArc _ inArc + 1 ].
18
comment text: 'Tries: ', try asString, '
19
approx: ', (inArc * 4 / try) asFloat asString.
20
(try \\ 10) isZero ifTrue: [(Delay forMilliseconds: 10) wait]