×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2014.2451 | Released: 2 Oct 2014, 2:23am | What's New | Download Now

math.cos()

Description:

Returns the cosine of a value (assumed to be in radians).

Syntax:

math.cos (x)

Example:

-- animate a circle along a path
local Ox, Oy = display.viewableContentWidth/2, display.viewableContentHeight/2
local myCircle = display.newCircle( Ox, Oy, 10 )
myCircle:setFillColor(128,128,200)
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 )

Parameters:

x
A number (assumed to be in radians).

Returns:

A number in the range [-1, 1].

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 1.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 1.0
  • Android:
    Corona SDK 2.0