设置旋转角度以匹配BPM值

问题描述 投票:0回答:1

我正试图在某些项目上设置旋转角度以匹配每分钟节拍计数器的速度。我有旋转的项目,但是我无法获得旋转值以匹配我从BPM中得到的每帧的度数值。

代码如下所示。我已经阅读了trig,我在圆圈上放置了圆点。它们根据表中的数字传播。我可以让它们旋转。但他们快速旋转。

在我的脑海里,它应该很简单:我按照60bpm的顺序运行16个音符,它在点之间给出22.5度,它们应该以每帧1.5度旋转,每秒15帧,与BPM一起旋转时钟。这就是我认为我已经设置的但是......它们的旋转速度要快得多。我已手动输入各种值,但它不匹配。


local SCREEN_FRAMERATE = 15
local angleRot  -- the gap between the dots, based upon the number of dots / 360
local rotateSpeed  -- the speed in degrees per second we need to rotate so the dots align with the sounds
local bbppmm  -- the beats per minute of the track



function init()
  -- OTHER CODE HERE


    -- set initial animation properties
  angleRot = (360 / initSequence.length)  -- set the offset between dots
  rotateSpeed = (angleRot/SCREEN_FRAMERATE)  -- work out the degrees per frame we need to rotate


  -- we use a metro to trigger n times per second (SCREEN_FRAMERATE)
  screen_refresh_metro = metro.init()
  screen_refresh_metro.event = function()
    angleRot = angleRot+1
    redraw()
  end
  screen_refresh_metro:start(1/SCREEN_FRAMERATE)
end



-- drawing the graphical interface
function redraw()
  screen.clear()

    screen.level(4)
    screen.rect(0,0,128,64)
    screen.fill()

    screen.level(1)
    screen.circle(64,32,11)
    screen.stroke()

    for i=1,initSequence.length do
    if initSequence.data[i] > 0 then
      screen.circle(
        math.cos((angleRot + rotateSpeed)*i)*11 + 64,  -- angle * radius + offset from zero
        math.sin((angleRot + rotateSpeed)*i)*11 + 32,  -- this line and the above place the circles on the larger circle
        initSequence.data[i] + (freqs[i]/600)  -- this line make the sequence circles the sizes they are
      )
    screen.fill()
    end
  end
    screen.update()
end

我希望这些点以BPM的速度旋转,因此以每分钟22.5度的速度在60bpm旋转。

我获得了更快的旋转速度,虽然它变得如此之快,但是日志无法跟上并且它可能只是随机的。

lua rotation trigonometry cairo
1个回答
1
投票

就像一个白痴我没有先将度数转换为弧度,正确的代码是:

math.cos(math.rad(angleRot)*i)*11 + 64,  -- angle * radius + offset from zero
math.sin(math.rad(angleRot)*i)*11 + 32,  -- this line and the above place the circles on the larger circle
© www.soinside.com 2019 - 2024. All rights reserved.