Difference between revisions of "Os.timer"
From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === <br /> Returns precise time in seconds relative to some arbitrary point.<br /> <br /> <source lang="lu...") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
| (10 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
| + | '''Class:''' [[os]]<br/> | ||
| + | |||
=== Description === | === Description === | ||
| − | + | Returns precise time in seconds relative to some arbitrary point. | |
| − | Returns precise time in seconds relative to some arbitrary point. | + | <syntaxhighlight lang="lua"> |
| − | < | + | (number) = os.timer() |
| − | + | </syntaxhighlight> | |
| − | (number) | + | |
| − | </ | + | === Return values === |
| − | '''Returns''' (number) | + | '''Returns''' (number) precise time in seconds relative to some arbitrary point<br/> |
| + | |||
| + | === Example === | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | local function onEnterFrame(event) | ||
| + | -- get the precise timer | ||
| + | local t = os.timer() | ||
| + | |||
| + | -- animate r,g,b multipliers of color transform | ||
| + | local r = (math.sin(t * 0.5 + 0.3) + 1) / 2 | ||
| + | local g = (math.sin(t * 0.8 + 0.2) + 1) / 2 | ||
| + | local b = (math.sin(t * 1.3 + 0.6) + 1) / 2 | ||
| + | |||
| + | -- set color transform | ||
| + | bitmap:setColorTransform(r, g, b, 1) | ||
| + | |||
| + | -- update the positions of dots | ||
| + | reddot:setX(90 + r * 280) | ||
| + | greendot:setX(90 + g * 280) | ||
| + | bluedot:setX(90 + b * 280) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{Os}} | ||
Latest revision as of 14:31, 13 July 2023
Available since: Gideros 2011.6
Class: os
Description
Returns precise time in seconds relative to some arbitrary point.
(number) = os.timer()
Return values
Returns (number) precise time in seconds relative to some arbitrary point
Example
local function onEnterFrame(event)
-- get the precise timer
local t = os.timer()
-- animate r,g,b multipliers of color transform
local r = (math.sin(t * 0.5 + 0.3) + 1) / 2
local g = (math.sin(t * 0.8 + 0.2) + 1) / 2
local b = (math.sin(t * 1.3 + 0.6) + 1) / 2
-- set color transform
bitmap:setColorTransform(r, g, b, 1)
-- update the positions of dots
reddot:setX(90 + r * 280)
greendot:setX(90 + g * 280)
bluedot:setX(90 + b * 280)
end