You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#define TPS 47
|
|
#define FADE_MS 500
|
|
|
|
#include <iostream>
|
|
#include <cmath>
|
|
|
|
using namespace std;
|
|
|
|
float current_vals[] = {10, 100, 45};
|
|
int target_vals[] = {255, 255, 0};
|
|
float fade_increments[] = {0.0, 0.0, 0.0};
|
|
|
|
int fade_ticks = ceil(FADE_MS / (float) TPS);
|
|
|
|
int val_iterator = 0;
|
|
int tick_iterator = 0;
|
|
|
|
int main() {
|
|
|
|
cout << "fade_ticks: " << fade_ticks << endl;
|
|
|
|
while (val_iterator < 3) {
|
|
fade_increments[val_iterator] = -((current_vals[val_iterator] - target_vals[val_iterator]) / (float) fade_ticks);
|
|
val_iterator++;
|
|
}
|
|
|
|
val_iterator = 0;
|
|
|
|
cout << "increments: " << fade_increments[0] << ", " << fade_increments[1] << ", " << fade_increments[2] << endl;
|
|
|
|
while (tick_iterator < fade_ticks) {
|
|
|
|
while (val_iterator < 3) {
|
|
|
|
current_vals[val_iterator] += fade_increments[val_iterator];
|
|
val_iterator++;
|
|
|
|
}
|
|
|
|
val_iterator = 0;
|
|
|
|
cout << tick_iterator << ": " << round(current_vals[0]) << ", " << round(current_vals[1]) << ", " << round(current_vals[2]) << endl;
|
|
|
|
tick_iterator++;
|
|
}
|
|
|
|
return 0;
|
|
} |