Type Function Library math.* Return value Number Revision Release 2024.3703 Keywords cosine, cos See also math.acos()
math.pi
math.sin()
Returns the cosine of x
(the angle in radians). The result is a number in the range [-1, 1]
.
-- animate a circle along a path local ox, oy = display.contentCenterX, display.contentCenterY local myCircle = display.newCircle( ox, oy, 20 ) myCircle:setFillColor( 1, 0, 0 ) local function onFrame( event ) myCircle.x = ( myCircle.x + 5 ) % display.viewableContentWidth myCircle.y = oy - math.cos( myCircle.x/20 ) * 100.0 end Runtime:addEventListener( "enterFrame", onFrame )