math.cos()

Type Function
Library math.*
Return value Number
Revision 2017.3060
Keywords cosine, cos
See also math.acos()
math.pi
math.sin()

Overview

Returns the cosine of x (the angle in radians). The result is a number in the range [-1, 1].

Syntax

math.cos( x )
x (required)

Number. The angle in radians.

Example

-- 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 )