Time stretcher example
Example to modify internal clock to make it run ten times faster. Setting internal clock tick speed affects to some engine's internal functionality, like some timers runs faster or slower. When tick is set to one, engine's clock goes hand in hand with system clock. Settings clock ticks does not modify or set operating system clock in any way, just engine's internal tick counting mechanism.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh time_stretch
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; time_stretch.ano
;
; To compile:
;
; $ ./build/ano ./examples/time_stretch/time_stretch.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME time_stretch
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple example to stretch internal clock
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Example to modify internal clock to make it run ten times faster. Setting
; internal clock tick speed affects to some engine's internal functionality,
; like some timers runs faster or slower. When tick is set to one, engine's
; clock goes hand in hand with system clock. Settings clock ticks does not
; modify or set operating system clock in any way, just engine's internal tick
; counting mechanism.
;
main [exit: 0] {
; Get system time in secs since epoch and set clock to that.
;
_time = time
clock_set (_time)
_n = time_strfmt (\
time: _time, \
format: "%Y-%m-%dT%H:%M:%S")
print "This moment is: " . _n . "\n\n"
; Get current clock tick count.
;
_tick = clock_get_ticks
; Set clock multiplier to one thousand to make it run thousand times
; faster.
;
_old_mul = clock_set_multiplier (1000)
print "Current clock multiplier is: " . _old_mul . "\n"
; Get current multiplier.
;
_new_mul = clock_get_multiplier
print "New clock multiplier is: " . _new_mul . "\n\n"
; Wait for a while to tick count to increase.
;
sleep (2, 0)
; Get clock tick count again.
;
_tick = clock_get_ticks
_n = time_strfmt (\
time: _tick, \
format: "%Y-%m-%dT%H:%M:%S")
print "Now the moment is: " . _n . ", which is ahead system time.\n"
}
; ------------------------------------------------------------------------------ ; time_stretch.w2c ; ; To compile: ; ; $ ./build/widget ./examples/time_stretch/time_stretch.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; time_stretch.m2c ; ; To compile: ; ; $ ./build/menu ./examples/time_stretch/time_stretch.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.