CLASS Greeter PUBLIC: ' This object owns the window's small piece of application state. X AS INTEGER Y AS INTEGER Moving AS INTEGER ' The last whole TIMER second painted; -1 requests the initial/final paint. LastSecond AS SINGLE DECLARE CONSTRUCTOR () DECLARE SUB Paint () END CLASS ' The window callbacks share one Greeter instance for this application's life. DIM SHARED App AS Greeter CONSTRUCTOR Greeter () THIS.X = 104 THIS.Y = 112 THIS.Moving = -1 THIS.LastSecond = -1! END CONSTRUCTOR SUB Greeter.Paint () DIM Now AS SINGLE ' TIMER is sampled by d/OS; INT makes the animation exactly once per second. Now = INT(TIMER) IF Now <> THIS.LastSecond THEN THIS.LastSecond = Now ' RND is deterministic here: the sample does not seed it from wall time. IF THIS.Moving <> 0 THEN ' Keep the native 6x10 greeting inside the portable 320x192 surface. THIS.X = INT(RND(1) * 241) THIS.Y = INT(RND(1) * 183) END IF ' A complete GFX Intent frame: clear, draw text, then make it visible. INTENT GFX.BEGIN_FRAME() INTENT GFX.FILL_RECT(0, 0, 320, 192, 2081) INTENT GFX.DRAW_TEXT(THIS.X, THIS.Y, "HELLO, WORLD!", 3, -1, 2081) INTENT GFX.PRESENT() END IF IF THIS.Moving <> 0 THEN ' Keep DRAW owed so the dispatcher can sample queued KEY/CLOSE events. SERVICE INVALIDATE() END IF END SUB ' OPEN creates the application's object and gives the window its initial title. WINDOW SUB OPEN() SERVICE SET_TITLE("Hello, world! Press any key.") App = NEW Greeter() END SUB ' DRAW delegates presentation to the object that owns the state. WINDOW SUB DRAW() App.Paint END SUB ' CLOSE releases that object deterministically. WINDOW SUB CLOSE() App = NOTHING END SUB ' Any key stops new positions, asks for one final paint, and leaves the window open. ON KEY SUB (K AS INTEGER) App.Moving = 0 App.LastSecond = -1! SERVICE SET_TITLE("Stopped") SERVICE INVALIDATE() END SUB