1 # Display digits of pi in a window, calculating in a separate thread.
2 # Compare ../scripts/pi.py.
8 from stdwinevents
import *
15 k
, a
, b
, a1
, b1
= 2l, 4l, 1l, 12l, 4l
18 p
, q
, k
= k
*k
, 2l*k
+1l, k
+1l
19 a
, b
, a1
, b1
= a1
, b1
, p
*a
+q
*a1
, p
*b
+q
*b1
24 digits
.append(`
int(d
)`
)
25 a
, a1
= 10l*(a
%b
), 10l*(a1
%b1
)
31 thread
.start_new_thread(worker
, ())
32 tw
= stdwin
.textwidth('0 ')
33 lh
= stdwin
.lineheight()
34 stdwin
.setdefwinsize(20 * tw
, 20 * lh
)
35 stdwin
.setdefscrollbars(0, 1)
36 win
= stdwin
.open('digits of pi')
37 options
= win
.menucreate('Options')
38 options
.additem('Auto scroll')
40 options
.check(0, autoscroll
)
43 type, w
, detail
= stdwin
.getevent()
48 (left
, top
), (right
, bottom
) = detail
49 digits_seen
= len(digits
)
50 d
= win
.begindrawing()
51 for i
in range(digits_seen
):
54 if top
-lh
< v
< bottom
:
55 d
.text((h
, v
), digits
[i
])
57 elif type == WE_TIMER
:
60 win
.settitle(`n`
+ ' digits of pi')
61 d
= win
.begindrawing()
62 for i
in range(digits_seen
, n
):
65 d
.text((h
, v
), digits
[i
])
68 height
= (v
+ 20*lh
) / (20*lh
) * (20*lh
)
69 win
.setdocsize(0, height
)
71 win
.show((0, v
), (h
+tw
, v
+lh
))
76 autoscroll
= (not autoscroll
)
77 options
.check(0, autoscroll
)