math.cos()

类型 函数
math.*
返回值 数字
修订 版本 2024.3703
关键词 余弦,cos
另请参阅 math.acos()
math.pi
math.sin()

概述

返回 x(以弧度表示的角度)的余弦值。结果是一个介于 [-1, 1] 范围内的数字。

语法

math.cos( x )
x (必填)

数字. 以弧度表示的角度。

示例

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