| Andreas Rozek |
|
TkLua ClockThe TkLua program described on this page was among the first scripts used to test the proper (and continuous) function of the author's TkLua distribution for Win32 platforms (and the resulting processor load).
Technical DescriptionThe display consists of a single canvas widget (tkcanvas) with "fixed" graphical elements for the clock's face and periodically replaced graphical elements for the three handles. Most of the work is done within function updateDisplay: two global variables per handle (e.g., HourHand and HourHand_Angle) store canvas index and actual angle of that handle. Upon every call of updateDisplay (i.e., once per second) the routine checks if any of the handles has moved since the last invocation - if so, the old canvas element for that handle will be replaced by a new one with the proper orientation (unfortunately, it is impossible to rotate existing canvas objects). Only the first invocation of updateDisplay does without this check (as there are no handle objects yet - these will now be created for the first time). As the calculation of any clock handle's orientation is based on the actual time, setting the system time manually or automatically (e.g., because of "daylight saving") will be reflected on the display within a single second. However, because of the simplicity of the underlying timer function (which is used to invoke updateDisplay periodically), the display quite often seems to "skip" a second due to processing delays caused by the TkLua program itself or by other simultaneously running applications. Nevertheless, on moderately loaded systems the shown time should match the actual system time with a tolerance of approximately +/- 1 second. The clock's tick marks and most of the handles (except that for seconds) are represented by closed rectangular polygons, whose nodes are brought into proper orientation with the aid of a bit of vector algebra. Only the second handle is represented by a single line, for the sake of simplicity. Apart from the "main program", "Clock" contains the following global functions (in alphabetical order):
The program itself is quite simple and should be self-explanatory enough to forego any further description. Source CodeThe source code of this program is available for download:
References
|
| http://www.Andreas-Rozek.de/Lua/Examples/Clock/index_en.html | (last Modification: 14.04.2002) |