1
2
3
4
5
6
7
8
9
10
11
12
13\starttext
14
15\useJSscripts[fld]
16
17\useJSpreamble[FieldStack]
18
19\definepapersize
20 [clock]
21 [width=2.5cm,
22 height=2.5cm]
23
24\setuppapersize
25 [clock][clock]
26
27\setuplayout
28 [header=0pt,
29 footer=0pt,
30 backspace=.25cm,
31 topspace=.25cm,
32 width=middle,
33 height=middle]
34
35\startJSpreamble stepper used now
36
37 var state = 0 ;
38 var more = 0 ;
39 var step = 0 ;
40
41 function stepclock() {
42 try {
43 if (more == 60) {
44 more = 0 ;
45 WalkField("more") ;
46 } else {
47 }
48 more = 1 ;
49 WalkField("clock") ;
50 this.dirty = false ;
51 } catch (e) {
52 }
53 }
54
55 function startclock() {
56 try {
57 if (state == 0) {
58 step = app.setInterval ("stepclock()", 1000) ;
59 step.count = 0 ;
60 state = 1 ;
61 } else if (state == 1) {
62 app.clearInterval (step) ;
63 state = 2 ;
64 } else if (state == 2) {
65 app.clearInterval (step) ;
66 ResetFields("more") ;
67 ResetFields("clock") ;
68 SetField("more", "1") ;
69 SetField("clock", "1") ;
70 more = 0 ;
71 state = 0 ;
72 }
73 } catch(e) {
74 }
75 }
76
77 function stopclock () {
78 try {
79 app.clearInterval(step) ;
80 } catch(e) {
81 }
82 }
83
84\stopJSpreamble
85
86\definereference[StopClock] [JS(stopclock)]
87\definereference[StartClock][JS(startclock)]
88
89\setupinteraction
90 [state=start,
91 closeaction={StopClock,ForgetChanges},
92 closepageaction={StopClock}]
93
94\startreusableMPgraphic{common}
95 drawoptions(withpen pencircle scaled 1mm withcolor .4white) ;
96 fill fullsquare scaled 2.5cm ;
97 drawoptions(withpen pencircle scaled 1mm withcolor .6green) ;
98 draw fullsquare scaled 2.5cm ;
99 drawoptions(withpen pencircle scaled 1mm withcolor .6red) ;
100 draw fullcircle scaled 2cm ;
101 drawoptions(withpen pencircle scaled 2mm withcolor .6yellow) ;
102 for i=1 upto 12 :
103 draw (0,1cm) rotated ((i-1)(36012)) ;
104 endfor ;
105\stopreusableMPgraphic
106
107\startuseMPgraphic{clock}
108 numeric stp ; stp := (\MPvar{n}-1)(36060) ;
109 pair p ; p := (0,\MPvar{l}-.5mm) ;
110 drawoptions(withpen pencircle scaled 1mm withcolor .6\MPvar{c}) ;
111 draw (origin -- p) rotated stp ;
112 draw (p shifted (-2mm,-2.5mm)pp shifted (2mm,-2.5mm)) rotated stp ;
113 setbounds currentpicture to fullsquare scaled 2cm ;
114 drawoptions(withpen pencircle scaled 2mm withcolor .6white) ;
115 draw origin ;
116\stopuseMPgraphic
117
118\defineoverlay [common] [\reuseMPgraphic{common}]
119\defineoverlay [start] [\overlaybutton{StartClock}]
120
121\setupbackgrounds
122 [page]
123 [background={common,start}]
124
125\let\clocklist\empty
126\let\morelist \empty
127
128\dorecurse {60} {
129 \appendtocommalist{step:#1}\clocklist
130 \definesymbol
131 [step:#1]
132 [\useMPgraphic{clock}{n=#1,l=1cm,c=blue}]
133 \appendtocommalist{more:#1}\morelist
134 \definesymbol
135 [more:#1]
136 [\useMPgraphic{clock}{n=#1,l=.75cm,c=green}]
137}
138
139\definefieldstack
140 [clock]
141 [\clocklist]
142 [width=2cm,height=2cm,offset=overlay,frame=off]
143
144\definefieldstack
145 [more]
146 [\morelist]
147 [width=2cm,height=2cm,offset=overlay,frame=off]
148
149\starttext
150
151 \startoverlay
152 {\fieldstack[more]}
153 {\fieldstack[clock]}
154 \stopoverlay
155
156\stoptext
157 |