Created
March 20, 2024 11:20
-
-
Save henriquelalves/8f6db4bc43b0e5161466ce972f7bf958 to your computer and use it in GitHub Desktop.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <libguile.h> | |
#include <math.h> | |
#include "raylib.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
static double x, y; | |
static double direction; | |
static int pendown; | |
static bool clear; | |
static SCM TortoiseReset() { | |
x = 400.0; | |
y = 300.0; | |
direction = 0; | |
pendown = 1; | |
clear = true; | |
return SCM_UNSPECIFIED; | |
} | |
static SCM TortoisePendown() { | |
pendown = 1; | |
return SCM_UNSPECIFIED; | |
} | |
static SCM TortoisePenup() { | |
pendown = 0; | |
return SCM_UNSPECIFIED; | |
} | |
static SCM TortoiseTurn(SCM degrees) { | |
const double value = scm_to_double(degrees); | |
direction += M_PI / 180.0 * value; | |
return SCM_UNSPECIFIED; | |
} | |
static SCM TortoiseMove(SCM length) { | |
const double value = scm_to_double(length); | |
double newX, newY; | |
newX = x + value * cos(direction); | |
newY = y + value * sin(direction); | |
if (pendown){ | |
DrawLine(x, y, newX, newY, BLACK); | |
} | |
x = newX; | |
y = newY; | |
return SCM_UNSPECIFIED; | |
} | |
static void* register_functions (void* data) | |
{ | |
scm_c_define_gsubr ("tortoise-reset", 0, 0, 0, &TortoiseReset); | |
scm_c_define_gsubr ("tortoise-penup", 0, 0, 0, &TortoisePenup); | |
scm_c_define_gsubr ("tortoise-pendown", 0, 0, 0, &TortoisePendown); | |
scm_c_define_gsubr ("tortoise-turn", 1, 0, 0, &TortoiseTurn); | |
scm_c_define_gsubr ("tortoise-move", 1, 0, 0, &TortoiseMove); | |
return NULL; | |
} | |
void *guile_thread(){ | |
scm_with_guile (®ister_functions, NULL); | |
char* argv[] = {"test", "--listen"}; | |
scm_shell (2, argv); | |
return NULL; | |
} | |
void* main(int argc, char* argv[]) { | |
pthread_t thread_id; | |
pthread_create(&thread_id, NULL, guile_thread, NULL); | |
const int screenWidth = 800; | |
const int screenHeight = 600; | |
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); | |
SetTargetFPS(60); | |
TortoiseReset(); | |
while (!WindowShouldClose()) | |
{ | |
BeginDrawing(); | |
if (clear) { | |
ClearBackground(RAYWHITE); | |
clear = false; | |
} | |
EndDrawing(); | |
} | |
CloseWindow(); | |
pthread_cancel(thread_id); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment