#include <3ds.h> #include #include "utilsconsole.hpp" #include "graphics.hpp" #include using namespace std; void mode_ugly_rainbow(void) { cout << "mode ugly rainbow" << endl; gfxSet3D(false); gspWaitForVBlank(); u16 width, height; t_color *frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { if (i % 30 < 10) rgb_set(frame[i], 0xFF0000); else if (i % 30 < 20) rgb_set(frame[i], 0x00FF00); else rgb_set(frame[i], 0x0000FF); } gfxFlushBuffers(); gfxSwapBuffers(); uc_pause(); } void mode_direction(void) { cout << "mode direction" << endl; gfxSet3D(false); gspWaitForVBlank(); u16 width, height; t_color *frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { if (i / 100 == 0) rgb_set(frame[i], 0xFF0000); else if (i / 100 == 1) rgb_set(frame[i], 0xFFFF00); else if (i / 100 == 2) rgb_set(frame[i], 0x00FF00); else if (i / 100 == 3) rgb_set(frame[i], 0x00FFFF); else if (i / 100 == 4) rgb_set(frame[i], 0x0000FF); else if (i / 100 == 5) rgb_set(frame[i], 0xFF00FF); else rgb_set(frame[i], 0); if (i % 100 >= 10) { frame[i][0] = frame[i][0] == 0xFF ? 0x7F : 0; frame[i][1] = frame[i][1] == 0xFF ? 0x7F : 0; frame[i][2] = frame[i][2] == 0xFF ? 0x7F : 0; } } gfxFlushBuffers(); gfxSwapBuffers(); uc_pause(); } void mode_XY(void) { cout << "mode XY" << endl; cout << "the higher x is, the redder the pixel is." << endl; cout << "the higher y is, the bluer the pixel is." << endl; gfxSet3D(false); gspWaitForVBlank(); u16 width, height; t_color *frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / width; int y = height - i % height - 1; if (x < 0) cout << "!!! x less than 0 !!!" << endl; if (y < 0) cout << "!!! y less than 0 !!!" << endl; if (x >= width) cout << "!!! x higher than width " << width << " !!!" << endl; if (y >= height) cout << "!!! y higher than height " << height << " !!!" << endl; rgb_set(frame[i], x > 255 ? 255 : x, 0, y > 255 ? 255 : y); } gfxFlushBuffers(); gfxSwapBuffers(); uc_pause(); } void mode_2d_square(void) { cout << "mode 2d square" << endl; gfxSet3D(false); gspWaitForVBlank(); u32 color = 0xFB2B2B; u16 width, height; t_color *frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height; int y = height - i % height - 1; if (x > 20 && x < 40 && y > 20 && y < 40) rgb_set(frame[i], 0xFFFFFF); else rgb_set(frame[i], color); } gfxFlushBuffers(); gfxSwapBuffers(); uc_pause(); } void mode_3d_square(void) { cout << "mode 3d square" << endl; float slider3d; slider3d = osGet3DSliderState(); cout << "3D level: " << slider3d << endl; gfxSet3D(true); if (!slider3d) { cout << "no 3D :(" << endl; uc_pause(); return; } gspWaitForVBlank(); u32 color = 0xFB2B2B; u16 width, height; t_color *frame; frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height; int y = height - i % height - 1; if (x > 15 && x < 35 && y > 20 && y < 40) rgb_set(frame[i], 0xFFFFFF); else rgb_set(frame[i], color); } frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height; int y = height - i % height - 1; if (x > 25 && x < 45 && y > 20 && y < 40) rgb_set(frame[i], 0xFFFFFF); else rgb_set(frame[i], color); } gfxFlushBuffers(); gfxSwapBuffers(); uc_pause(); } static u32 rainbow_color(int i) { while (i < 0) i += 24; switch (i % 24) { // sorry case 0: return 0xFF0000; case 1: return 0xFF3F00; case 2: return 0xFF7F00; case 3: return 0xFFBF00; case 4: return 0xFFFF00; case 5: return 0xBFFF00; case 6: return 0x7FFF00; case 7: return 0x3FFF00; case 8: return 0x00FF00; case 9: return 0x00FF3F; case 10: return 0x00FF7F; case 11: return 0x00FFBF; case 12: return 0x00FFFF; case 13: return 0x00BFFF; case 14: return 0x007FFF; case 15: return 0x003FFF; case 16: return 0x0000FF; case 17: return 0x3F00FF; case 18: return 0x7F00FF; case 19: return 0xBF00FF; case 20: return 0xFF00FF; case 21: return 0xFF00BF; case 22: return 0xFF007F; case 23: return 0xFF003F; } return 0xFFFFFF; } void mode_ugly_3d_rainbow(void) { cout << "mode ugly 3d rainbow" << endl; cout << "A to return..." << endl; gfxSet3D(true); while (aptMainLoop()) { gspWaitForVBlank(); int thick = 20; float slider3d = osGet3DSliderState(); int depth = slider3d * 30; u16 width, height; t_color *frame; frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height; int y = height - i % height - 1; (void)y; rgb_set(frame[i], rainbow_color((x + depth) / thick)); } frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height; int y = height - i % height - 1; (void)y; rgb_set(frame[i], rainbow_color((x - depth) / thick)); } gfxFlushBuffers(); gfxSwapBuffers(); hidScanInput(); if (hidKeysDown() & KEY_A) break; } } void mode_yellue(void) { cout << "mode yellue" << endl; int left_red = 0; int left_green = 0; int left_blue = 2; int right_red = 2; int right_green = 2; int right_blue = 0; const auto to255 = [] (int value) { return value > 0 ? value * 128 - 1 : 0; }; static const int menu_size = 7; static const s_uc_menu_element menu[] = { {"left red ", true, &left_red, 0, 2}, {"left green", true, &left_green, 0, 2}, {"left blue ", true, &left_blue, 0, 2}, {"right red ", true, &right_red, 0, 2}, {"right green", true, &right_green, 0, 2}, {"right blue ", true, &right_blue, 0, 2}, {"back", false, NULL, 0, 0}, }; static auto menuVec = vector(menu, menu + menu_size); gfxSet3D(true); while (aptMainLoop()) { gspWaitForVBlank(); u16 width, height; t_color *frame; frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) rgb_set(frame[i], to255(left_red), to255(left_green), to255(left_blue)); frame = (t_color *) gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, &height, &width); for (int i = 0; i < width * height; i++) rgb_set(frame[i], to255(right_red), to255(right_green), to255(right_blue)); gfxFlushBuffers(); gfxSwapBuffers(); if (uc_menu(menuVec) == 6) break; } } static void mode_3d_moving_square() { int ans = 0; int z = 0; gfxSet3D(true); while (aptMainLoop() && ans != 1) { static const int menu_size = 2; static const s_uc_menu_element menu[] = { {"z ", true, &z, -100, 100}, {"back", false, NULL, 0, 0}, }; static auto menuVec = vector(menu, menu + menu_size); ans = uc_menu(menuVec); gspWaitForVBlank(); static const u32 color_back = 0xFFFFFF; static const u32 color_square = 0xFFFF00; u16 width, height; t_color *frame; frame = (t_color *) gfxGetFramebuffer( GFX_TOP, GFX_LEFT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height - z; if (x < 0 || x >= width) continue; int y = height - i % height - 1; if (x > 190 && x < 210 && y > 100 && y < 120) rgb_set(frame[i], color_square); else rgb_set(frame[i], color_back); } frame = (t_color *) gfxGetFramebuffer( GFX_TOP, GFX_RIGHT, &height, &width); for (int i = 0; i < width * height; i++) { int x = i / height + z; if (x < 0 || x >= width) continue; int y = height - i % height - 1; if (x > 190 && x < 210 && y > 100 && y < 120) rgb_set(frame[i], color_square); else rgb_set(frame[i], color_back); } gfxFlushBuffers(); gfxSwapBuffers(); } } int main(void) {; gfxInitDefault(); consoleInit(GFX_BOTTOM, NULL); while (aptMainLoop()) { static const int menu_size = 9; static const s_uc_menu_element menu[] = { {"ugly rainbow", false, NULL, 0, 0}, {"direction", false, NULL, 0, 0}, {"XY", false, NULL, 0, 0}, {"2D square", false, NULL, 0, 0}, {"3D square", false, NULL, 0, 0}, {"ugly 3D rainbow", false, NULL, 0, 0}, {"yellue", false, NULL, 0, 0}, {"3D moving square", false, NULL, 0, 0}, {"quit", false, NULL, 0, 0}, }; static auto menuVec = vector(menu, menu + menu_size); int ans = uc_menu(menuVec); switch (ans) {} if (ans == 0) mode_ugly_rainbow(); if (ans == 1) mode_direction(); if (ans == 2) mode_XY(); if (ans == 3) mode_2d_square(); if (ans == 4) mode_3d_square(); if (ans == 5) mode_ugly_3d_rainbow(); if (ans == 6) mode_yellue(); if (ans == 7) mode_3d_moving_square(); if (ans == 8) break; gfxSet3D(false); } gfxExit(); }