diff options
author | nathansmith117 <nathansmith117@sdf.org> | 2025-02-03 13:46:19 +0000 |
---|---|---|
committer | nathansmith117 <nathansmith117@sdf.org> | 2025-02-03 13:46:19 +0000 |
commit | 305c224104be6558f2ece595a47cf29348b60d66 (patch) | |
tree | f36af90ce04dade5b520a24c77176ca7ebb4ef65 /src | |
download | sldj-305c224104be6558f2ece595a47cf29348b60d66.tar.gz sldj-305c224104be6558f2ece595a47cf29348b60d66.tar.bz2 sldj-305c224104be6558f2ece595a47cf29348b60d66.zip |
first commit
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/sldj.c | 68 | ||||
-rw-r--r-- | src/sldj.h | 22 | ||||
-rw-r--r-- | src/sldjConfig.h | 12 | ||||
-rw-r--r-- | src/util.c | 2 | ||||
-rw-r--r-- | src/util.h | 13 |
6 files changed, 133 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a02b023 --- /dev/null +++ b/src/main.c @@ -0,0 +1,16 @@ +#include <raylib.h> +#include "sldj.h" + +int main() +{ + Sldj sldj; + initSldj(&sldj); + + while (!WindowShouldClose()) + { + updateSldj(&sldj); + } + + closeSldj(&sldj); + return 0; +} diff --git a/src/sldj.c b/src/sldj.c new file mode 100644 index 0000000..a2b0c47 --- /dev/null +++ b/src/sldj.c @@ -0,0 +1,68 @@ +#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(); +} + diff --git a/src/sldj.h b/src/sldj.h new file mode 100644 index 0000000..4db6afb --- /dev/null +++ b/src/sldj.h @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> +#include <raylib.h> +#include <math.h> +#include <stdint.h> + +#include "sldjConfig.h" +#include "util.h" + +#ifndef SLDJ_H +#define SLDJ_H + +typedef struct Sldj { + RenderTexture screenTexture; + int frameCounter; +} Sldj; + +void initSldj(Sldj* sldj); +void updateSldj(Sldj* sldj); +void closeSldj(Sldj* sldj); + +#endif diff --git a/src/sldjConfig.h b/src/sldjConfig.h new file mode 100644 index 0000000..53fa4e9 --- /dev/null +++ b/src/sldjConfig.h @@ -0,0 +1,12 @@ +#ifndef CONFIG_SLDJ_H +#define CONFIG_SLDJ_H + +#define WINDOW_WIDTH 960 +#define WINDOW_HEIGHT 720 + +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 + +#define FRAME_RATE 24 + +#endif diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..b7e445c --- /dev/null +++ b/src/util.c @@ -0,0 +1,2 @@ +#include "util.h" + diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..110aae7 --- /dev/null +++ b/src/util.h @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> + +#ifndef UTIL_H +#define UTIL_H + +#define SET_BIT(b, n) (b | (0x1 << n)) +#define CLEAR_BIT(b, n) (b & ~(0x1 << n)) +#define IS_BIT_SET(b, n) ((b >> n) & 0x1) +#define TOGGLE_BIT(b, n) (b ^ (0x1 << n)) +#define HAS_FLAG(v, f) ((v & f) == f) + +#endif |