当前位置: 首页>>代码示例>>C++>>正文


C++ Pixel::getTransitionDuration方法代码示例

本文整理汇总了C++中Pixel::getTransitionDuration方法的典型用法代码示例。如果您正苦于以下问题:C++ Pixel::getTransitionDuration方法的具体用法?C++ Pixel::getTransitionDuration怎么用?C++ Pixel::getTransitionDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pixel的用法示例。


在下文中一共展示了Pixel::getTransitionDuration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void ColorSoupEffect::update(unsigned long delta) {
  if (myColorPallette->getNumColors() < 1) {
    return;
  }

  //Re-calculate pixel values
  for (int i=0; i < myPixelStrip->getNumPixels(); ++i) {
    Pixel *pixel = myPixelStrip->getPixel(i);
    pixel->setTimeInState(pixel->getTimeInState() + delta);

    //Set pixel on if twinklePos matches and not already on
    boolean stateComplete = pixel->getTimeInState() >= pixel->getTransitionDuration();

    if (!stateComplete) {

      /*
      uint32_t startRed = myPixelStrip->getRed(pixel->getInitialColor());
      uint32_t endRed = myPixelStrip->getRed(pixel->getDestinationColor());
      uint32_t newRed = startRed + ((endRed - startRed) * pixel->getTimeInState() / pixel->getTransitionDuration());

      uint32_t startGreen = myPixelStrip->getGreen(pixel->getInitialColor());
      uint32_t endGreen = myPixelStrip->getGreen(pixel->getDestinationColor());
      uint32_t newGreen = startGreen + ((endGreen - startGreen) * pixel->getTimeInState() / pixel->getTransitionDuration());

      uint32_t startBlue = myPixelStrip->getBlue(pixel->getInitialColor());
      uint32_t endBlue = myPixelStrip->getBlue(pixel->getDestinationColor());
      uint32_t newBlue = startBlue + ((endBlue - startBlue) * pixel->getTimeInState() / pixel->getTransitionDuration());
      /**/

      /*
      uint8_t *init = (uint8_t*)&(pixel->getInitialColor());
      uint8_t *dest = (uint8_t*)&(pixel->getDestinationColor());
      /**/

      /*
      uint32_t startRed = *init[0];
      uint32_t endRed = myPixelStrip->getRed(pixel->getDestinationColor());
      uint32_t newRed = startRed + ((endRed - startRed) * pixel->getTimeInState() / pixel->getTransitionDuration());

      uint32_t startGreen = myPixelStrip->getGreen(pixel->getInitialColor());
      uint32_t endGreen = myPixelStrip->getGreen(pixel->getDestinationColor());
      uint32_t newGreen = startGreen + ((endGreen - startGreen) * pixel->getTimeInState() / pixel->getTransitionDuration());

      uint32_t startBlue = myPixelStrip->getBlue(pixel->getInitialColor());
      uint32_t endBlue = myPixelStrip->getBlue(pixel->getDestinationColor());
      uint32_t newBlue = startBlue + ((endBlue - startBlue) * pixel->getTimeInState() / pixel->getTransitionDuration());
      /**/

      /**/
//      uint32_t startRed = (pixel->getInitialColor() & 0xff0000);
//      startRed = startRed >> 16;
//      uint32_t endRed = (pixel->getDestinationColor() & 0xff0000);
//      uint8_t newRed = startRed + ((endRed - startRed) * pixel->getTimeInState() / pixel->getTransitionDuration());
//      uint8_t newBlue = 0;
//      uint8_t newGreen = 0;
      /**/

      /*
      uint32_t startBlue = (pixel->getInitialColor() & 0x00ff00);
      uint32_t endBlue = (pixel->getDestinationColor() & 0x00ff00);
      startBlue = startBlue >> 8;
      uint32_t newBlue = startBlue + ((endBlue - startBlue) * pixel->getTimeInState() / pixel->getTransitionDuration());

      uint32_t startGreen = (pixel->getInitialColor() & 0x0000ff);
      uint32_t endGreen = (pixel->getDestinationColor() & 0x0000ff);
      uint32_t newGreen = startGreen + ((endGreen - startGreen) * pixel->getTimeInState() / pixel->getTransitionDuration());
      /**/

      /*
      uint32_t newColor = Adafruit_NeoPixel::Color(newRed, newGreen, newBlue);
      pixel->setColor(newColor);
      /**/

      /**/
      EffectUtils::colorBlend(pixel->getInitialColor(), pixel->getDestinationColor(), pixel->getTimeInState() / pixel->getTransitionDuration());
      /**/

    } else {
      /*
      pixel->setInitialColor(0);
      pixel->setColor(0);
      pixel->setDestinationColor(Adafruit_NeoPixel::Color(255, 0, 0));
      pixel->setTransitionDuration(2000);
      pixel->changeState(TWINKLE_IN);
      /**/

      /**/
      pixel->changeState(TWINKLE_IN);
      pixel->transition(255,
        myColorPallette->getRandomColor(),
        20000);
//        (rand() % (myMaxTwinkleTime - myMinTwinkleTime)) + myMinTwinkleTime);
      /**/
    }
  }
}
开发者ID:Bit-Rot,项目名称:StarBarfBlinky,代码行数:96,代码来源:ColorSoupEffect.cpp


注:本文中的Pixel::getTransitionDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。