void Beacon::paint(RNLights & lights) { float angle = getAnimationCycles(); float height = (float)info.z / (float)constants.pyramidRadiusFromGround; uint32_t platformZValue = height * 255; for(int i = 0; i < lights.getNumPixels(); i++) { if (parameters.onlyExterior && !info.isExteriorLED(i)) { lights.setPixelColor(i, parameters.baseGradient.getColor(platformZValue)); continue; }; float diff = (info.getGlobalAngle(i) - angle) * parameters.numBeacons; float a = diff - roundf(diff); if (a < 0) a = -a; if (a < parameters.width) { uint8_t gradientPosition = a*256/parameters.width; uint32_t color = parameters.gradient.getColor(gradientPosition); lights.setPixelColor(i,color); } else { lights.setPixelColor(i, parameters.baseGradient.getColor(platformZValue)); } } info.showActivityWithSparkles(lights); }
void Snow::paint(RNLights & lights) { unsigned long ms = getAnimationMillis(); snow.fade(ms); do { addSnowFlake(); lastUpdateMillis += parameters.msPerFlake; } while (lastUpdateMillis < ms); if (info.getTaps()) for(int i = 0; i < parameters.flakesPerTap; i++) addSnowFlake(); lights.copyPixels(snow); lights.setBrightness(parameters.brightness); }
void DRAnimation0::paint(RNLights & lights) { uint8_t hue = (getAnimationMillis() / 2) % 256; lights.setAllPixelColors((i==0)?MAX_BRIGHTNESS:0,(i==1)?MAX_BRIGHTNESS:0,(i==2)?MAX_BRIGHTNESS:0); if ( info.getTaps() ) { info.printf("Tappy\n"); i = (i+1)%3; } }
void capOverallBrightness(RNLights & lights) { uint8_t avgPixelBrightness = lights.getAvgPixelBrightness(); uint8_t avgBrightness = avgPixelBrightness * lights.getBrightness()/256; if (avgBrightness > constants.brightnessChunkSize) { int goal = scaleBrightness(avgBrightness); int newBrightness = goal * 255 / avgPixelBrightness; #ifdef RN_PRINT_BRIGHTNESS_ADJUSTMENTS info->printf("Avg brightness is %d/%d, goal is %d, Reducing brightness from %d -> %d\n", avgPixelBrightness, avgBrightness, goal, lights->getBrightness(), newBrightness); #endif /* RN_PRINT_BRIGHTNESS_ADJUSTMENTS */ lights.setBrightness(newBrightness); } // else info.printf("Avg brightness is %d/%d\n", avgPixelBrightness, avgBrightness); }
void RNInfo::showActivityWithBrightness(RNLights & lights, uint16_t minBrightness) { int maxAdjustment = (256 - minBrightness); float activity = getLocalActivity() * 6; if (activity > 1.0) activity = 1.0; minBrightness += maxAdjustment * activity / 4; if (minBrightness >= 256) return; int b = 256; int age = timeSinceLastTap() - 100; if (age > 0) b = 256 - age/2; if (b < minBrightness) b = minBrightness; int newBrightness = b * lights.getBrightness() / 256; #ifdef RN_PRINT_BRIGHTNESS_ADJUSTMENTS printf("Changing brightness %d -> %d\n", lights.getBrightness(), newBrightness); #endif /* RN_PRINT_BRIGHTNESS_ADJUSTMENTS */ lights.setBrightness(newBrightness); }
void Beacon::paint(RNLights & lights) { float angle = getAnimationMillis() * parameters.rpm/60000.0; for(int i = 0; i < lights.getNumPixels(); i++) { float diff = info.getGlobalAngle(i) - angle; float a = diff - roundf(diff); if (a < 0) a = -a; if (a < parameters.width) { uint8_t gradientPosition = a*256/parameters.width; uint32_t color = parameters.gradient.getColor(gradientPosition); lights.setPixelColor(i,color); } } info.showActivityWithSparkles(lights); }
void FlashAttack::paint(RNLights & lights) { int value = (int)(255 - info.timeSinceLastTap()*parameters.tapMultiplier); int value2 = parameters.minimumValue+info.getLocalActivity() * parameters.activityMultiplier; value = max(value, value2); value = min(value, 255); lights.setAllPixelHSVs(getUnsignedTweakValue(),255,value); }
void Mute::paint(RNLights & lights) { uint8_t brightness = 20 + getUnsignedTweakValue()/5; lights.setAllPixelColors(brightness, brightness, brightness); }
void MovingFaces::paint(RNLights & lights) { unsigned long now = info.getGlobalMillis(); if (now > targetTime) { // Rotate points A, B and D. Point C stay the top platform. short * backupA = pointA; pointA = pointB; pointB = pointD; pointD = backupA; distanceAD = distancePointFromPoint(pointA, pointD); startTime = now; targetTime = now + parameters.duration; } float ratio = (float) (now - startTime) / (float) (targetTime - startTime); AHEasingFunction easingFunction = getEasingFunction(parameters.easingMode, parameters.curveType); ratio = easingFunction(ratio); float vector[3] = { (pointD[0] - pointA[0]) * ratio, (pointD[1] - pointA[1]) * ratio, (pointD[2] - pointA[2]) * ratio }; long a, b, c, d; getPlanEquation( pointA[0] + vector[0], pointA[1] + vector[1], pointA[2] + vector[2], pointB[0], pointB[1], pointB[2], pointC[0], pointC[1], pointC[2], a, b, c, d); for (int i = 0; i < lights.getNumPixels(); i++) { float xLED = getLEDXPosition(i) + info.x; float yLED = getLEDYPosition(i) + info.y; float zLED = info.z; long distance = distancePointFromPlan( a, b, c, d, xLED, yLED, zLED); if (parameters.summitColorMode) { if (abs(distance) <= parameters.thickness) { lights.setPixelColor(i, gradient3Colors.getPixelColor(i)); } } else { RNGradient *gradientToUse = 0; float point = 0; if (abs(distance) <= parameters.thickness) { gradientToUse = &(parameters.gradientInside); point = (float) (parameters.thickness - abs(distance)) / (float) parameters.thickness; } else { gradientToUse = &(parameters.gradientOutside); point = (float) abs(distance) / (float) distanceAD; } uint32_t color = gradientToUse->getColor(point * 255); lights.setPixelColor(i, color); } } lastUpdate = now; }
void RNInfo::showActivityWithSparkles(RNLights & lights) { lights.applyBrightness(); lights.copyPixelsMax(sparkles); }