Mouse following thing and template fix

This commit is contained in:
Casey 2024-05-30 12:28:06 +03:00
parent 058a007265
commit ee68131914
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
4 changed files with 49 additions and 1 deletions

View File

@ -1,7 +1,7 @@
#include <raylib.h>
int main(int argc, char **argv) {
InitWindow(__WINDOW_WIDTH, __WINDOW_HEIGHT, "__PROJECT_NAME");
InitWindow(__WINDOW_WIDTH, __WINDOW_HEIGHT, "__PROJECT");
while (!WindowShouldClose()) {
BeginDrawing();

1
vis/follow-mouse/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
follow-mouse

12
vis/follow-mouse/Makefile Normal file
View File

@ -0,0 +1,12 @@
CFLAGS += -Wall -Wextra `exec pkg-config --cflags raylib`
LDFLAGS := -lm `pkg-config --libs raylib`
follow-mouse: main.c
$(CC) $(CFLAGS) main.c $(LDFLAGS) -o follow-mouse
clean:
$(RM) follow-mouse
run: follow-mouse
./follow-mouse

35
vis/follow-mouse/main.c Normal file
View File

@ -0,0 +1,35 @@
// 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();
}
}