From 51c2ff25e60b1cf039a0a91b502a5caa48789462 Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Mon, 3 Nov 2025 16:52:39 -0800 Subject: [PATCH] added rotation matrix to the bizear curves --- source/main.c | 10 +++++-- source/nomi.c | 78 ++++++++++++++++++++++++++++++++++++--------------- source/nomi.h | 16 ++++++++++- 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/source/main.c b/source/main.c index 86b5a5a..14fddce 100644 --- a/source/main.c +++ b/source/main.c @@ -119,7 +119,10 @@ int main (int argc, char *argv[]) { unsigned char keyPressed = 0; branch b = { - .startPos = (struct tart_vec2){term_current_size().x/2,term_current_size().y- 10}, + .startPos = (nomi_vec2){term_current_size().x/2.0,term_current_size().y/2.0}, + }; + branch b1 = { + .startPos = (nomi_vec2){30,term_current_size().y- 10}, }; @@ -149,12 +152,12 @@ int main (int argc, char *argv[]) { for (;!__Close__;) { // LOOP START + tart_restore_window(&window); + tart_restore_buffer(tart_get_buffer(&window, 0)); if(keyPressed) { tart_draw_window(&window, 0); - tart_restore_window(&window); - tart_restore_buffer(tart_get_buffer(&window, 0)); char c = term_tinput(); @@ -260,6 +263,7 @@ int main (int argc, char *argv[]) { DrawBranch(&b, &window, 0); + //DrawBranch(&b1, &window, 0); tart_draw_window(&window, 0); if(mode == COMMAND_MODE) { diff --git a/source/nomi.c b/source/nomi.c index 8eb978f..1a9d4e7 100644 --- a/source/nomi.c +++ b/source/nomi.c @@ -5,6 +5,7 @@ #define SPIREL_MOD 0.618055f + struct nomiSpirel { struct tart_cell selected_cell; struct tart_cell unselected_cell; @@ -42,6 +43,31 @@ void CreaetBranch(trunk* trunk); * */ branch* LocateBranch(); + +float a = -3; +nomi_vec2 RotatePoint(nomi_vec2 or,nomi_vec2 t, nomi_vec2 d) { + nomi_vec2 pos; + + //float a = atan2(d.y, d.x) - 3.14f/2; + a+= 0.001f; + pos.x = (t.x * cos(a) - t.y * sin(a)); + pos.y = (t.x * sin(a) + t.y * cos(a))/2; + + + return pos; +} + +nomi_curve RotateCurve(nomi_curve og, nomi_vec2 d) { + nomi_curve c; + c.start = og.start; // start is the origin so there is no need to rotate + c.start = RotatePoint(og.start, og.start, d); // this point + + c.c0 = RotatePoint(og.start,og.c0,d); + c.c1 = RotatePoint(og.start,og.c1,d); + c.end = RotatePoint(og.start,og.end,d); + return c; +} + /* * Draw Branch */ @@ -49,22 +75,26 @@ void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) { struct tart_cell cell = NULL_CELL; cell.display = '*'; struct nomiSpirel spirel; + nomi_curve c; int SizeOfFile = 600; char cellChart[] = {'%','*','\\','/','l','&','7','+','=','^',':'}; unsigned int iderations = 0; - struct tart_vec2 pos0 = { - (( 3) * -1)+branch->startPos.x, - (( 0/2) * -1)+branch->startPos.y}; - struct tart_vec2 c0 = { - (( 25) * -1)+branch->startPos.x, - ((35/2) * -1)+branch->startPos.y}; // controle point 0 - struct tart_vec2 c1 = { - (( -10) * -1)+branch->startPos.x, - ((35/2) * -1)+branch->startPos.y}; // controle point 1 - struct tart_vec2 pos1 = { - (( 3) * -1)+branch->startPos.x, - ((10/2) * -1)+branch->startPos.y}; + if(branch->curve.start.x == 0) { + branch->curve.start = (nomi_vec2){ + 0, + 0}; + branch->curve.c0 = (nomi_vec2){ + (( 25) * -1), + ((35/2.f) * -1)}; // controle point 0 + branch->curve.c1 = (nomi_vec2){ + (( -10) * -1), + ((35/2.f) * -1)}; // controle point 1 + branch->curve.end = (nomi_vec2){ + (( 3) * -1), + ((20/2.f) * -1)}; + c = RotateCurve(branch->curve, (nomi_vec2){0,0}); + } struct tart_vec2 dpos = {0,0}; float count = 0; @@ -78,21 +108,25 @@ void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) { // 3 = right iderations++; + cell.display = cellChart[rand_r(&iderations)%11]; dpos = (struct tart_vec2){ - (1-count)*((1-count)*((1-count)*pos0.x + count * c0.x) + - count * ((1-count)*c0.x + count*c1.x)) + - count * ((1-count)*((1-count)*c0.x + count * c1.x) + - count * ((1-count)*c1.x + pos1.x)), - (1-count)*((1-count)*((1-count)*pos0.y + count * c0.y) + count * - ((1-count)*c0.y + count*c1.y)) + - count *((1-count)*((1-count)*c0.y + count * c1.y) + - count * ((1-count)*c1.y + pos1.y)), + (1-count)*((1-count)*((1-count)*c.start.x + count * c.c0.x) + + count * ((1-count)*c.c0.x + count*c.c1.x)) + + count * ((1-count)*((1-count)*c.c0.x + count * c.c1.x) + + count * ((1-count)*c.c1.x + c.end.x)), + (1-count)*((1-count)*((1-count)*c.start.y + count * c.c0.y) + count * + ((1-count)*c.c0.y + count*c.c1.y)) + + count *((1-count)*((1-count)*c.c0.y + count * c.c1.y) + + count * ((1-count)*c.c1.y + c.end.y)), }; - - tart_draw_cell_position(tart_get_buffer(w, b), cell, dpos); + dpos.x += branch->startPos.x; + dpos.y += branch->startPos.y; + if(dpos.x >= 0 && dpos.y >=0) { + tart_draw_cell_position(tart_get_buffer(w, b), cell, dpos); + } diff --git a/source/nomi.h b/source/nomi.h index a40f118..5a0a01a 100644 --- a/source/nomi.h +++ b/source/nomi.h @@ -24,13 +24,27 @@ typedef unsigned int branchId; +typedef struct { + double x; + double y; +} nomi_vec2; + +typedef struct { + nomi_vec2 start; + nomi_vec2 c0; + nomi_vec2 c1; + nomi_vec2 end; + +} nomi_curve; + // All of the different notes typedef struct { char* text; // This is the data that is in that branch branchId children[MAX_CHILDREN]; // holds the branchIds of its children void* parent; // points the the branches parent char type; // holds the type as in if this struct is a branch or a trunk - struct tart_vec2 startPos; // the starting position of the branch + nomi_vec2 startPos; // the starting position of the branch + nomi_curve curve; branchId id; // This holds the branch id. } branch;