things/vis/follow-mouse/main.c

36 lines
890 B
C
Raw Normal View History

2024-05-30 12:28:06 +03:00
// x-run: make run
#include <raylib.h>
#include <raymath.h>
#include <string.h>
#define TRAIL_LENGTH 360
int main(int argc, char **argv) {
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "vis/follow-mouse");
SetTargetFPS(120);
Vector2 trail[TRAIL_LENGTH];
Vector2 ex_trail[TRAIL_LENGTH];
Vector2 pos = { 0, 0 };
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(BLACK);
memmove(&trail[0], &trail[1], sizeof(Vector2) * (TRAIL_LENGTH - 1));
trail[TRAIL_LENGTH - 1] = GetMousePosition();
DrawLineStrip(trail, TRAIL_LENGTH, RED);
pos = Vector2Lerp(pos, trail[TRAIL_LENGTH - 1], 0.125);
DrawCircleLines(pos.x, pos.y, 8, WHITE);
memmove(&ex_trail[0], &ex_trail[1], sizeof(Vector2) * (TRAIL_LENGTH - 1));
ex_trail[TRAIL_LENGTH - 1] = pos;
DrawLineStrip(ex_trail, TRAIL_LENGTH, GREEN);
EndDrawing();
}
}