void Visualizer::VisThread() { float red, grn, blu; while (1) { Update(); //Overflow background step if (bkgd_step >= 360) bkgd_step = 0; //Loop through all 256x64 pixels in visualization image for (int x = 0; x < 256; x++) { for (int y = 0; y < 64; y++) { float brightness = bkgd_bright * (255.0f / 100.0f); //Draw active background switch (bkgd_mode) { //None (black) case 0: pixels[y][x] = RGB(0, 0, 0); break; //Original case 1: red = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f)) + 1); grn = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f) - (6.28f / 3)) + 1); blu = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f) + (6.28f / 3)) + 1); pixels[y][x] = RGB((bkgd_bright/2) * red, (bkgd_bright/2) * grn, (bkgd_bright/2) * blu); break; //Rainbow case 2: { int hsv_h = ((bkgd_step + (256 - x)) % 360); hsv_t hsv = { hsv_h, 255, bkgd_bright }; pixels[y][x] = hsv2rgb(&hsv); } break; //Color Wheel case 3: { float hue = bkgd_step + (int)(180 + atan2(y - 32.1, x - 128.1) * (180.0 / 3.14159))%360; hsv_t hsv2 = { hue, 255, bkgd_bright }; pixels[y][x] = hsv2rgb(&hsv2); } break; //Follow Foreground case 4: pixels[y][x] = GetAmplitudeColor(255 - (fft[5] * 255), 255, fft[5] * 255 * (bkgd_bright/100.0f)); break; //White case 5: pixels[y][x] = RGB(brightness, brightness, brightness); break; //Red case 6: pixels[y][x] = RGB(brightness, 0, 0); break; //Orange case 7: pixels[y][x] = RGB(brightness, brightness / 2, 0); break; //Yellow case 8: pixels[y][x] = RGB(brightness, brightness, 0); break; //Green case 9: pixels[y][x] = RGB(0, brightness, 0); break; //Cyan case 10: pixels[y][x] = RGB(0, brightness, brightness); break; //Blue case 11: pixels[y][x] = RGB(0, 0, brightness); break; //Purple case 12: pixels[y][x] = RGB(brightness, 0, brightness); break; } //Draw foreground if (y > 3) { if (fft[x] >((1 / 64.0f)*(64.0f - y))) { pixels[y][x] = GetAmplitudeColor(y, 64, 255); } } if (y < 2) { if (x < 128) { if ((fft[5] - 0.05f) >((1 / 128.0f)*(127-x))) { pixels[y][x] = GetAmplitudeColor(x, 128, 255); } } else { if ((fft[5] - 0.05f) >((1 / 128.0f)*((x-128)))) { pixels[y][x] = GetAmplitudeColor(127-(x-128), 128, 255); } } } //Draw brightness based visualizer for single LED devices if (y == 3) { float brightness = fft[5] * 255; switch (single_color_mode) { //None case 0: pixels[y][x] = RGB(0, 0, 0); break; //Follow Foreground case 1: pixels[y][x] = GetAmplitudeColor(255 - brightness, 255, brightness); break; //Follow Background: case 2: break; //White case 3: pixels[y][x] = RGB(brightness, brightness, brightness); break; //Red case 4: pixels[y][x] = RGB(brightness, 0, 0); break; //Orange case 5: pixels[y][x] = RGB(brightness, brightness / 2, 0); break; //Yellow case 6: pixels[y][x] = RGB(brightness, brightness, 0); break; //Green case 7: pixels[y][x] = RGB(0, brightness, 0); break; //Cyan case 8: pixels[y][x] = RGB(0, brightness, brightness); break; //Blue case 9: pixels[y][x] = RGB(0, 0, brightness); break; //Purple case 10: pixels[y][x] = RGB(brightness, 0, brightness); break; } } } } //Increment background step bkgd_step++; Sleep(15); } }
void Visualizer::VisThread() { float red, grn, blu; while (1) { Update(); //Overflow background step if (bkgd_step >= 360) bkgd_step = 0; //Loop through all 256x64 pixels in visualization image for (int x = 0; x < 256; x++) { for (int y = 0; y < 64; y++) { //Draw active background switch (bkgd_mode) { case 0: pixels[y][x] = RGB(0, 0, 0); break; case 1: red = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f)) + 1); grn = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f) - (6.28f / 3)) + 1); blu = (sin((((((int)(x * (360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f) + (6.28f / 3)) + 1); pixels[y][x] = RGB(bkgd_bright * red, bkgd_bright * grn, bkgd_bright * blu); break; case 2: int hsv_h = ((bkgd_step + (256 - x)) % 360); hsv_t hsv = { hsv_h, 255, bkgd_bright }; pixels[y][x] = hsv2rgb(&hsv); break; } if (y > 3) { if (fft[x] >((1 / 64.0f)*(64.0f - y))) { pixels[y][x] = GetAmplitudeColor(y, 64); } } if (y < 2) { if (x < 128) { if ((fft[5] - 0.05f) >((1 / 128.0f)*(127-x))) { pixels[y][x] = GetAmplitudeColor(x, 128); } } else { if ((fft[5] - 0.05f) >((1 / 128.0f)*((x-128)))) { pixels[y][x] = GetAmplitudeColor(127-(x-128), 128); } } } } } //Increment background step bkgd_step++; Sleep(15); } }