Fixed randChangePxl to now use the PXL structure

This allows the animation to happen very quickly without consuming
all the resources while waiting for an approiate random number
This commit is contained in:
David Todd (c0de) 2018-07-24 21:21:38 -05:00
parent 777464a735
commit ae3a642e10

View File

@ -206,22 +206,41 @@ void scanChangePxl(int src[TOTALPXLS][3], int dst[TOTALPXLS][3], int dlytime, in
* - dlytime - The amount of time (in ms) to keep the image on the display * - dlytime - The amount of time (in ms) to keep the image on the display
* - anitime - The amount of time (in ms) between drawing each pixel during the transition; the lower this number, the faster the transition * - anitime - The amount of time (in ms) between drawing each pixel during the transition; the lower this number, the faster the transition
*/ */
void randChangePxl(int src[256][3], int dst[256][3], int dlytime, int anitime) { void randChangePxl(int src[TOTALPXLS][3], int dst[TOTALPXLS][3], int dlytime, int anitime) {
int changed[256]; resetActiveState();
for (int i=0; i<256; i++){
// Image that we are animating from
for (int i = 0; i < TOTALPXLS; i++){
pixols[i].active = false;
matrix.setPixelColor(i, src[i][0], src[i][1], src[i][2]); matrix.setPixelColor(i, src[i][0], src[i][1], src[i][2]);
} }
matrix.show(); matrix.show();
delay(dlytime); delay(dlytime);
for (int i=0; i<256; i++){ // Image that we are animating to
int selected = random(0, 256); while (activePixelCount() < TOTALPXLS) {
// If the selected pixel was inside changed array, select a new one... randomSeed(A1);
// Add selected to changed array int selected = random(0, TOTALPXLS);
matrix.setPixelColor(selected, dst[selected][0], dst[selected][1], dst[selected][2]);
// Select only pixels that have not already been set
if (pixols[selected].active) {
while (true) {
selected = random(0, TOTALPXLS);
if (!pixols[selected].active) {
break;
}
}
}
pixols[selected].active = true;
matrix.setPixelColor(selected, dst[selected][0],
dst[selected][1],
dst[selected][2]);
matrix.show(); matrix.show();
delay(anitime); delay(anitime);
if (activePixelCount() >= TOTALPXLS) break;
} }
delay(dlytime); delay(dlytime);