void RGBFade::crossFade(int R, int G, int B) { int stepR = calculateStep(prevR, R); int stepG = calculateStep(prevG, G); int stepB = calculateStep(prevB, B); for (int i = 0; i <= 1020; i++) { redVal = calculateVal(stepR, redVal, i); grnVal = calculateVal(stepG, grnVal, i); bluVal = calculateVal(stepB, bluVal, i); analogWrite(redPin, redVal); // Write current values to LED pins analogWrite(grnPin, grnVal); analogWrite(bluPin, bluVal); delayMicroseconds(crossWait); // Pause for 'wait' milliseconds before resuming the loop if (DEBUG) { // If we want serial output, print it at the if (i == 0 or i % loopCount == 0) { // beginning, and every loopCount times Serial.print("Loop/RGB: #"); Serial.print(i); Serial.print(" | "); Serial.print(redVal); Serial.print(" / "); Serial.print(grnVal); Serial.print(" / "); Serial.println(bluVal); } DEBUG += 1; } } // Update current values for next loop prevR = redVal; prevG = grnVal; prevB = bluVal; }
void Player::generatePath(const Position& target) { // todo und finalized liste leeren todo.clear(); finalized.clear(); // Ziel-Knoten in finalized Liste einfügen finalized.insert(mapElement(target, Node(target, 0))); // aktuellen Knoten auf Ziel-Knoten setzen current = &finalized.at(target); // rekursive Funktion aufrufen calculateStep(target); }
QWidget *QgsProcessingNumericWidgetWrapper::createWidget() { const QgsProcessingParameterNumber *numberDef = static_cast< const QgsProcessingParameterNumber * >( parameterDefinition() ); const QVariantMap metadata = numberDef->metadata(); const int decimals = metadata.value( QStringLiteral( "widget_wrapper" ) ).toMap().value( QStringLiteral( "decimals" ), 6 ).toInt(); switch ( type() ) { case QgsProcessingGui::Standard: case QgsProcessingGui::Modeler: case QgsProcessingGui::Batch: { // lots of duplicate code here -- but there's no common interface between QSpinBox/QDoubleSpinBox which would allow us to avoid this QAbstractSpinBox *spinBox = nullptr; switch ( numberDef->dataType() ) { case QgsProcessingParameterNumber::Double: mDoubleSpinBox = new QgsDoubleSpinBox(); mDoubleSpinBox->setExpressionsEnabled( true ); mDoubleSpinBox->setDecimals( decimals ); // guess reasonable step value for double spin boxes if ( !qgsDoubleNear( numberDef->maximum(), std::numeric_limits<double>::max() ) && !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() + 1 ) ) { double singleStep = calculateStep( numberDef->minimum(), numberDef->maximum() ); singleStep = std::max( singleStep, std::pow( 10, -decimals ) ); mDoubleSpinBox->setSingleStep( singleStep ); } spinBox = mDoubleSpinBox; break; case QgsProcessingParameterNumber::Integer: mSpinBox = new QgsSpinBox(); mSpinBox->setExpressionsEnabled( true ); spinBox = mSpinBox; break; } spinBox->setToolTip( parameterDefinition()->toolTip() ); double max = 999999999; if ( !qgsDoubleNear( numberDef->maximum(), std::numeric_limits<double>::max() ) ) { max = numberDef->maximum(); } double min = -999999999; if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) ) { min = numberDef->minimum(); } if ( mDoubleSpinBox ) { mDoubleSpinBox->setMinimum( min ); mDoubleSpinBox->setMaximum( max ); } else { mSpinBox->setMinimum( static_cast< int >( min ) ); mSpinBox->setMaximum( static_cast< int >( max ) ); } if ( numberDef->flags() & QgsProcessingParameterDefinition::FlagOptional ) { mAllowingNull = true; if ( mDoubleSpinBox ) { mDoubleSpinBox->setShowClearButton( true ); const double min = mDoubleSpinBox->minimum() - 1; mDoubleSpinBox->setMinimum( min ); mDoubleSpinBox->setValue( min ); } else { mSpinBox->setShowClearButton( true ); const int min = mSpinBox->minimum() - 1; mSpinBox->setMinimum( min ); mSpinBox->setValue( min ); } spinBox->setSpecialValueText( tr( "Not set" ) ); } else { if ( numberDef->defaultValue().isValid() ) { // if default value for parameter, we clear to that bool ok = false; if ( mDoubleSpinBox ) { double defaultVal = numberDef->defaultValue().toDouble( &ok ); if ( ok ) mDoubleSpinBox->setClearValue( defaultVal ); } else { int intVal = numberDef->defaultValue().toInt( &ok ); if ( ok ) mSpinBox->setClearValue( intVal ); } } else if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) ) { // otherwise we clear to the minimum, if it's set if ( mDoubleSpinBox ) mDoubleSpinBox->setClearValue( numberDef->minimum() ); else mSpinBox->setClearValue( static_cast< int >( numberDef->minimum() ) ); } else { // last resort, we clear to 0 if ( mDoubleSpinBox ) { mDoubleSpinBox->setValue( 0 ); mDoubleSpinBox->setClearValue( 0 ); } else { mSpinBox->setValue( 0 ); mSpinBox->setClearValue( 0 ); } } } if ( mDoubleSpinBox ) connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, [ = ] { emit widgetValueHasChanged( this ); } ); else if ( mSpinBox ) connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ), this, [ = ] { emit widgetValueHasChanged( this ); } ); return spinBox; }; } return nullptr; }
void Player::calculateStep(const Position& target) { // Abbruchbedienung (Spieler-Position erreicht) if (current != 0 && current->position == position) return; // Nachbarn des aktuellen Knoten beziehen std::list<Node> neighbors = map.getNeighbors(current->position); for (std::list<Node>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) { Node& neighbor = *it; // wenn Kosten größer 0 und noch nicht finalized if (neighbor.costs > 0 && finalized.find(neighbor.position) == finalized.end()) { // in todo Liste nach Nachbarn suchen nodeMap::iterator todoIt = todo.find(neighbor.position); // wenn noch nicht in todo Liste oder aktuelle Kosten kleiner als Kosten in todo Liste if (todoIt == todo.end() || todoIt->second.costs > neighbor.costs + current->costs) { // wenn in todo Liste, Nachbarn aus todo Liste löschen if (todoIt != todo.end()) todo.erase(todoIt); // Nachfolger auf aktuellen Knoten setzen neighbor.next = current; // Kosten um bisherige Kosten erhöhen neighbor.costs += current->costs; // in todo Liste einfügen todo.insert(mapElement(neighbor.position, neighbor)); } } } current = &(todo.begin()->second); int currentHeuristic = getHeuristic(current->position, position); // in todo Liste nach billigstem Knoten suchen for (nodeMap::iterator it = todo.begin(); it != todo.end(); ++it) { Node& node = it->second; // Heuristik berechnen int heuristic = getHeuristic(node.position, position); // Gesamtkosten vergleichen if (node.costs + heuristic < current->costs + currentHeuristic) { currentHeuristic = heuristic; current = &node; } } // Knoten in die finalized List einfügen finalized.insert(mapElement(current->position, *current)); current = &finalized.at(current->position); // Knoten aus der todo Liste löschen todo.erase(current->position); calculateStep(target); }