Skip to content

Instantly share code, notes, and snippets.

@NAEL2XD
Created May 9, 2025 00:10
Show Gist options
  • Select an option

  • Save NAEL2XD/6395e8c48eefeb2c5afc0c39d4dfd2ca to your computer and use it in GitHub Desktop.

Select an option

Save NAEL2XD/6395e8c48eefeb2c5afc0c39d4dfd2ca to your computer and use it in GitHub Desktop.
3DS: Epileptic Staring
#include <stdio.h>
#include <stdlib.h>
#include <citro2d.h>
#include <math.h>
#include <3ds.h>
// Prework those things.
C2D_Text renderText;
C2D_Font defaultFont;
C2D_TextBuf g_staticBuf;
u32 borderColor;
u32 textColor;
// Use custom function to init first before starting process.
void initBeforeProcess() {
// If some are NULL, set their default value.
if (defaultFont == NULL) defaultFont = C2D_FontLoadSystem(CFG_REGION_USA);
if (g_staticBuf == NULL) g_staticBuf = C2D_TextBufNew(4096);
borderColor = C2D_Color32(0x00, 0x00, 0x00, 0xAA);
textColor = C2D_Color32(0xFF, 0xFF, 0xFF, 0xFF);
C2D_TextBufClear(g_staticBuf);
}
void renderBorderText(char *text, float x, float y, float borderSize, float size) {
initBeforeProcess();
// Clear and Parse to make text work.
C2D_TextFontParse(&renderText, defaultFont, g_staticBuf, text);
C2D_TextOptimize(&renderText);
// If the x variable is -1, then it will be set to middle.
if (x == -1) x = (-(renderText.width * size) / 2) + 200;
// Do the trick.
int pos[8][2] = {{-1, -1}, {1, -1}, {-1, 1}, {1, 1}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}};
for (int i = 0; i < 8; i++) {
float finalMult = borderSize * size;
C2D_DrawText(&renderText, C2D_WithColor, x + (pos[i][0] * finalMult), y + (pos[i][1] * finalMult), 0.5f, size, size, borderColor);
}
C2D_DrawText(&renderText, C2D_WithColor, x, y, 0.5f, size, size, textColor);
}
int main() {
gfxInitDefault();
consoleInit(GFX_BOTTOM, NULL);
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
C2D_Prepare();
C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
printf("COLORFUL!!!");
u8 col[3][2] = {{84, 1}, {169, 1}, {254, 1}};
u64 startTime = osGetTime();
while (aptMainLoop()) {
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown & KEY_START) break;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(top, C2D_Color32(col[0][0], col[1][0], col[2][0], 255));
C2D_SceneBegin(top);
for (int i = 0; i < 3; i++) {
col[i][0] += col[i][1];
if (col[i][0] == 255) col[i][1] = col[i][1] == 1 ? -1 : 1;
}
u64 currentTime = osGetTime();
u64 elapsedTime = currentTime - startTime;
char txt[128];
snprintf(txt, sizeof(txt), "Elapsed time: %llu seconds.", elapsedTime / 1000);
renderBorderText(txt, -1, 200, 1.1, 0.9);
C3D_FrameEnd(0);
}
gfxExit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment