【问题标题】:Setting a rotation angle to match a BPM value设置旋转角度以匹配 BPM 值
【发布时间】:2019-04-08 00:12:08
【问题描述】:

我正在尝试设置某些项目的旋转角度以匹配每分钟节拍计数器的速度。我让项目旋转,但我无法让旋转值与我从 BPM 计算出的每帧度数值相匹配。

代码如下所示。我已经阅读了三角函数,我将圆上的点放置在了下方。它们根据表中的数字进行分布。我可以让它们旋转。但是它们旋转得很快。

在我的脑海中应该很简单:我有 16 个音符以 60bpm 的速度运行,这使我的点之间的角度为 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 的速度旋转,因此以 60bpm 每秒 22.5 度的速度旋转。

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

【问题讨论】:

    标签: lua rotation trigonometry cairo


    【解决方案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
    

    【讨论】:

    • 考虑删除您的帖子。这是一段非常具体的代码中的一个小错误。它不太可能对其他人有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多