Compare commits

1 Commits

Author SHA1 Message Date
5e8a6685dc finished with rework 2026-03-16 14:59:05 -07:00
3 changed files with 114 additions and 51 deletions

View File

@@ -1,6 +1,5 @@
#ifndef TART_H
#define TART_H
#include <string.h>
#define TART_UTF8
#ifdef __cplusplus
@@ -25,20 +24,37 @@ typedef char t_char;
#endif
/* tart_color
*
* Tart Color uses three bytes. Each byte reperesents a color.
* There is no alpha
* */
typedef struct {
tart_byte r;
tart_byte g;
tart_byte b;
} tart_color;
/* TART_PALET_SIZE
*
* Every Window has an amount of palettes that it is alicated to use.
* This number is what is defined here. To change this number just add a
* #define for your program.
*
* DEFALT: 32
* */
#ifndef TART_PALET_SIZE
#define TART_PALET_SIZE 32
#endif
/* tart_palette
*
* Every Palette contains a forground color and a background color.
* */
typedef struct {
tart_color forground;
tart_color background;
} tart_pallet;
} tart_palette;
typedef struct {
int x;
@@ -68,7 +84,7 @@ typedef struct {
* The tart window will have the window size and all of the buffers.
**/
typedef struct {
tart_pallet pallet[TART_PALET_SIZE];
tart_palette palette[TART_PALET_SIZE];
tart_vec2 homePosition;
tart_vec2 windowSize;
tart_vec2 terminalSize;

View File

@@ -39,9 +39,9 @@ int tart_create_buffer(tart_window* w) {
#else
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[0].forground.r,
w->pallet[0].forground.g,
w->pallet[0].forground.b,
w->palette[0].forground.r,
w->palette[0].forground.g,
w->palette[0].forground.b,
#ifdef TART_UTF8
L' '
#else
@@ -97,12 +97,12 @@ int flush_buffer(tart_window* w) {
#else
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[0].background.r,
w->pallet[0].background.g,
w->pallet[0].background.b,
w->pallet[0].forground.r,
w->pallet[0].forground.g,
w->pallet[0].forground.b,
w->palette[0].background.r,
w->palette[0].background.g,
w->palette[0].background.b,
w->palette[0].forground.r,
w->palette[0].forground.g,
w->palette[0].forground.b,
#ifdef TART_UTF8
L' '
#else
@@ -121,12 +121,12 @@ int flush_buffer(tart_window* w) {
void flush_palets(tart_window* w) {
for(int i = 0; i < TART_PALET_SIZE; i++) {
w->pallet[i].background.r = 0;
w->pallet[i].background.g = 0;
w->pallet[i].background.b = 0;
w->pallet[i].forground.r = 254;
w->pallet[i].forground.g = 254;
w->pallet[i].forground.b = 254;
w->palette[i].background.r = 0;
w->palette[i].background.g = 0;
w->palette[i].background.b = 0;
w->palette[i].forground.r = 254;
w->palette[i].forground.g = 254;
w->palette[i].forground.b = 254;
}
}
@@ -151,10 +151,10 @@ int tart_init(tart_window* w) {
}
void tart_disable_cusor() {
write(STDOUT_FILENO, "\e[?25l", 8);
write(STDOUT_FILENO, "\e[?25l", 6);
}
void tart_enable_cusor() {
write(STDOUT_FILENO, "\e[?25h", 8);
write(STDOUT_FILENO, "\e[?25h", 6);
}
int tart_close(tart_window* w) {
@@ -220,12 +220,12 @@ int tart_insert_cell(tart_window* w, tart_byte p, t_char c) {
#else
"\e[48;2;%03hhu;%03hhu;%03hhum\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[p].background.r,
w->pallet[p].background.g,
w->pallet[p].background.b,
w->pallet[p].forground.r,
w->pallet[p].forground.g,
w->pallet[p].forground.b,
w->palette[p].background.r,
w->palette[p].background.g,
w->palette[p].background.b,
w->palette[p].forground.r,
w->palette[p].forground.g,
w->palette[p].forground.b,
c
);

View File

@@ -4,8 +4,11 @@
#include <signal.h>
#include <stdio.h>
#include <locale.h>
#include <time.h>
#define jump tart_move_cursor
#define FPS 60
#define FRAME_TIME (1000.0 / FPS)
int e = 1;
@@ -33,6 +36,24 @@ void draw_button(tart_window *w,const t_char* label, tart_vec2 position) {
}
tart_printf(w, 1, T"━━━┛");
}
void limit_fps(int fps) {
static struct timespec last_time;
struct timespec current_time;
double frame_time = 1.0 / fps;
clock_gettime(CLOCK_MONOTONIC, &current_time);
double elapsed = (current_time.tv_sec - last_time.tv_sec) +
(current_time.tv_nsec - last_time.tv_nsec) / 1e9;
if (elapsed < frame_time) {
double sleep_time = frame_time - elapsed;
struct timespec sleep = { (time_t)sleep_time, (long)(sleep_time * 1e9) };
nanosleep(&sleep, NULL);
}
last_time = current_time;
}
int main(int argc, char *argv[])
{
@@ -47,23 +68,29 @@ int main(int argc, char *argv[])
tart_init(&w);
tart_disable_cusor();
w.pallet[0].background.r = 0;
w.pallet[0].background.g = 0;
w.pallet[0].background.b = 0;
w.pallet[0].forground.r = 0;
w.pallet[0].forground.g = 0;
w.pallet[0].forground.b = 0;
w.palette[0].background.r = 0;
w.palette[0].background.g = 0;
w.palette[0].background.b = 0;
w.palette[0].forground.r = 0;
w.palette[0].forground.g = 0;
w.palette[0].forground.b = 0;
w.pallet[1].forground.r = 0xff;
w.pallet[1].forground.g = 0x00;
w.pallet[1].forground.b = 0xcc;
w.palette[1].forground.r = 0xff;
w.palette[1].forground.g = 0x00;
w.palette[1].forground.b = 0xcc;
w.pallet[2].forground.r = 0x3b;
w.pallet[2].forground.g = 0x3b;
w.pallet[2].forground.b = 0x3b;
w.palette[2].forground.r = 0x3b;
w.palette[2].forground.g = 0x3b;
w.palette[2].forground.b = 0x3b;
jump(&w, (tart_vec2){1,1});
jump(&w, (tart_vec2){1,2});
int x = 0;
float xBounce = 30.0f;
float xFlip = 0.1f;
float yBounce = 30.0f;
float yFlip = -0.40f;
clock_t last_frame_time = clock();
double frame_time_ms;
while(e != 0) {
tart_draw(&w);
@@ -75,41 +102,61 @@ int main(int argc, char *argv[])
tart_printf(&w,1, T"this is\na new line test\nyay");
tart_jump(&w, (tart_vec2){3,14});
tart_printf(&w,2, T"this is\na new line test\nyay");
if(w.pallet[1].forground.r == 254) {
tart_printf(&w,2, T"y position %f", yBounce);
if((w.windowSize.x - 2 <= xBounce && xFlip > 0.0f) || (2 > xBounce && xFlip < 0.0f)) {
xFlip *= -1 ;
}
if(((w.windowSize.y * 2) - 2 <= yBounce && yFlip > 0.0f) || (2 > yBounce && yFlip < 0.0f)) {
yFlip *= -1 ;
}
yBounce += yFlip;
xBounce += xFlip;
tart_jump(&w, (tart_vec2){xBounce, yBounce/2});
if((int)yBounce % 2 == 0){
tart_printf(&w, 1, T"");
} else {
tart_printf(&w, 1, T"");
}
if(w.palette[1].forground.r == 254) {
color0 = 0;
}
if(w.pallet[1].forground.r == 0) {
if(w.palette[1].forground.r == 0) {
color0 = 1;
}
if(w.pallet[1].forground.g == 254) {
if(w.palette[1].forground.g == 254) {
color1 = 0;
}
if(w.pallet[1].forground.g == 0) {
if(w.palette[1].forground.g == 0) {
color1 = 1;
}
if(w.pallet[1].forground.b == 254) {
if(w.palette[1].forground.b == 254) {
color2 = 0;
}
if(w.pallet[1].forground.b == 0) {
if(w.palette[1].forground.b == 0) {
color2 = 1;
}
if(color0 == 1) {
w.pallet[1].forground.r++;
w.palette[1].forground.r++;
}else {
w.pallet[1].forground.r--;
w.palette[1].forground.r--;
}
if(color1 == 1) {
w.pallet[1].forground.g++;
w.palette[1].forground.g++;
}else {
w.pallet[1].forground.g--;
w.palette[1].forground.g--;
}
if(color2 == 1) {
w.pallet[1].forground.b++;
w.palette[1].forground.b++;
}else {
w.pallet[1].forground.b--;
w.palette[1].forground.b--;
}
limit_fps(60);
}