本文整理汇总了C++中FadeChannel::calculateCurrent方法的典型用法代码示例。如果您正苦于以下问题:C++ FadeChannel::calculateCurrent方法的具体用法?C++ FadeChannel::calculateCurrent怎么用?C++ FadeChannel::calculateCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FadeChannel
的用法示例。
在下文中一共展示了FadeChannel::calculateCurrent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateCurrent
void FadeChannel_Test::calculateCurrent()
{
FadeChannel fch;
fch.setStart(0);
fch.setTarget(255);
// Simple: 255 ticks to fade from 0 to 255
for (uint time = 0; time < 255; time++)
QCOMPARE(fch.calculateCurrent(255, time), uchar(time));
// Same thing, but the value should stay at 255 same after 255 ticks
for (uint time = 0; time <= 512; time++)
QCOMPARE(fch.calculateCurrent(255, time), uchar(MIN(time, 255)));
// Simple reverse: 255 ticks to fade from 255 to 0
fch.setStart(255);
fch.setTarget(0);
for (uint time = 0; time <= 255; time++)
QCOMPARE(fch.calculateCurrent(255, time), uchar(255 - time));
// A bit more complex involving decimals that don't produce round integers
fch.setStart(13);
fch.setTarget(147);
QCOMPARE(fch.calculateCurrent(13, 0), uchar(13));
QCOMPARE(fch.calculateCurrent(13, 1), uchar(23));
QCOMPARE(fch.calculateCurrent(13, 2), uchar(33));
QCOMPARE(fch.calculateCurrent(13, 3), uchar(43));
QCOMPARE(fch.calculateCurrent(13, 4), uchar(54));
QCOMPARE(fch.calculateCurrent(13, 5), uchar(64));
QCOMPARE(fch.calculateCurrent(13, 6), uchar(74));
QCOMPARE(fch.calculateCurrent(13, 7), uchar(85));
QCOMPARE(fch.calculateCurrent(13, 8), uchar(95));
QCOMPARE(fch.calculateCurrent(13, 9), uchar(105));
QCOMPARE(fch.calculateCurrent(13, 10), uchar(116));
QCOMPARE(fch.calculateCurrent(13, 11), uchar(126));
QCOMPARE(fch.calculateCurrent(13, 12), uchar(136));
QCOMPARE(fch.calculateCurrent(13, 13), uchar(147));
// One more to check slower operation (200 ticks for 144 steps)
fch.setStart(245);
fch.setTarget(101);
QCOMPARE(fch.calculateCurrent(200, 0), uchar(245));
QCOMPARE(fch.calculateCurrent(200, 1), uchar(245));
QCOMPARE(fch.calculateCurrent(200, 2), uchar(244));
QCOMPARE(fch.calculateCurrent(200, 3), uchar(243));
QCOMPARE(fch.calculateCurrent(200, 4), uchar(243));
QCOMPARE(fch.calculateCurrent(200, 5), uchar(242));
QCOMPARE(fch.calculateCurrent(200, 6), uchar(241));
QCOMPARE(fch.calculateCurrent(200, 7), uchar(240));
QCOMPARE(fch.calculateCurrent(200, 8), uchar(240));
QCOMPARE(fch.calculateCurrent(200, 9), uchar(239));
QCOMPARE(fch.calculateCurrent(200, 10), uchar(238));
QCOMPARE(fch.calculateCurrent(200, 11), uchar(238));
// Skip...
QCOMPARE(fch.calculateCurrent(200, 100), uchar(173));
QCOMPARE(fch.calculateCurrent(200, 101), uchar(173));
QCOMPARE(fch.calculateCurrent(200, 102), uchar(172));
// Skip...
QCOMPARE(fch.calculateCurrent(200, 198), uchar(103));
QCOMPARE(fch.calculateCurrent(200, 199), uchar(102));
QCOMPARE(fch.calculateCurrent(200, 200), uchar(101));
}