#include "sldj.h" void initSldj(Sldj* sldj) { InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Scanline DJ"); SetWindowState(FLAG_WINDOW_RESIZABLE); SetTargetFPS(FRAME_RATE); sldj->screenTexture = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT); sldj->frameCounter = 0; } uint16_t noise = 0; Color scanPoint(uint16_t x, uint16_t y, int frame) { noise ^= frame; noise ^= x ^ y; return (Color){.r = (y >> (6 - noise)) ^ (frame << 4), .g = noise >> x, .b = 0, .a = 255}; } void updateSldj(Sldj* sldj) { BeginDrawing(); // Scan image. BeginTextureMode(sldj->screenTexture); uint16_t xScaled = 0; uint16_t yScaled = 0; for (uint16_t y = 0; y < SCREEN_HEIGHT; ++y) { xScaled = 0; for (uint16_t x = 0; x < SCREEN_WIDTH; ++x) { DrawPixel(x, y, scanPoint(xScaled, yScaled, sldj->frameCounter)); xScaled += 65536 / SCREEN_WIDTH; } yScaled += 65536 / SCREEN_HEIGHT; } EndTextureMode(); // Draw scanned image. DrawTexturePro( sldj->screenTexture.texture, (Rectangle){0.0, 0.0, SCREEN_WIDTH, SCREEN_HEIGHT}, (Rectangle){0.0, 0.0, SCREEN_WIDTH, SCREEN_HEIGHT}, (Vector2){0.0, 0.0}, 0.0, WHITE ); EndDrawing(); ++sldj->frameCounter; } void closeSldj(Sldj* sldj) { UnloadRenderTexture(sldj->screenTexture); CloseWindow(); }