made it so that branches would be drawn on branches
This commit is contained in:
@@ -118,13 +118,8 @@ int main (int argc, char *argv[]) {
|
|||||||
char commandInput[255] = "";
|
char commandInput[255] = "";
|
||||||
unsigned char keyPressed = 0;
|
unsigned char keyPressed = 0;
|
||||||
|
|
||||||
branch b = {
|
branch b = create_branch(NULL, (nomi_vec2){0,1});
|
||||||
.startPos = (nomi_vec2){term_current_size().x/2.0,term_current_size().y/2.0},
|
branch b1 = create_branch(&b,(nomi_vec2){1,1});
|
||||||
};
|
|
||||||
branch b1 = {
|
|
||||||
.startPos = (nomi_vec2){30,term_current_size().y- 10},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Window Createion
|
// Window Createion
|
||||||
struct tart_window window = tart_create_window();
|
struct tart_window window = tart_create_window();
|
||||||
@@ -155,6 +150,8 @@ int main (int argc, char *argv[]) {
|
|||||||
tart_restore_window(&window);
|
tart_restore_window(&window);
|
||||||
tart_restore_buffer(tart_get_buffer(&window, 0));
|
tart_restore_buffer(tart_get_buffer(&window, 0));
|
||||||
|
|
||||||
|
b = create_branch(NULL, (nomi_vec2){0,1});
|
||||||
|
b1 = create_branch(&b,(nomi_vec2){1,4*2});
|
||||||
|
|
||||||
if(keyPressed) {
|
if(keyPressed) {
|
||||||
tart_draw_window(&window, 0);
|
tart_draw_window(&window, 0);
|
||||||
@@ -263,7 +260,7 @@ int main (int argc, char *argv[]) {
|
|||||||
|
|
||||||
|
|
||||||
DrawBranch(&b, &window, 0);
|
DrawBranch(&b, &window, 0);
|
||||||
//DrawBranch(&b1, &window, 0);
|
DrawBranch(&b1, &window, 0);
|
||||||
|
|
||||||
tart_draw_window(&window, 0);
|
tart_draw_window(&window, 0);
|
||||||
if(mode == COMMAND_MODE) {
|
if(mode == COMMAND_MODE) {
|
||||||
|
|||||||
@@ -43,13 +43,15 @@ void CreaetBranch(trunk* trunk);
|
|||||||
* */
|
* */
|
||||||
branch* LocateBranch();
|
branch* LocateBranch();
|
||||||
|
|
||||||
|
float t = 0;
|
||||||
|
|
||||||
float a = -3;
|
|
||||||
|
float a = 0;
|
||||||
nomi_vec2 RotatePoint(nomi_vec2 or,nomi_vec2 t, nomi_vec2 d) {
|
nomi_vec2 RotatePoint(nomi_vec2 or,nomi_vec2 t, nomi_vec2 d) {
|
||||||
nomi_vec2 pos;
|
nomi_vec2 pos;
|
||||||
|
|
||||||
//float a = atan2(d.y, d.x) - 3.14f/2;
|
float a = atan2(d.y, d.x) - 3.14f/2;
|
||||||
a+= 0.001f;
|
//a+= 0.001f;
|
||||||
pos.x = (t.x * cos(a) - t.y * sin(a));
|
pos.x = (t.x * cos(a) - t.y * sin(a));
|
||||||
pos.y = (t.x * sin(a) + t.y * cos(a))/2;
|
pos.y = (t.x * sin(a) + t.y * cos(a))/2;
|
||||||
|
|
||||||
@@ -68,33 +70,70 @@ nomi_curve RotateCurve(nomi_curve og, nomi_vec2 d) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branch create_branch(branch* parent, nomi_vec2 d) {
|
||||||
|
branch branch;
|
||||||
|
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)};
|
||||||
|
branch.curve = RotateCurve(branch.curve, d);
|
||||||
|
|
||||||
|
if(parent != NULL) {
|
||||||
|
float count = .5;
|
||||||
|
nomi_vec2 dpos = {
|
||||||
|
(1-count)*((1-count)*((1-count)*parent->curve.start.x + count * parent->curve.c0.x) +
|
||||||
|
count * ((1-count)*parent->curve.c0.x + count*parent->curve.c1.x)) +
|
||||||
|
count * ((1-count)*((1-count)*parent->curve.c0.x + count * parent->curve.c1.x) +
|
||||||
|
count * ((1-count)*parent->curve.c1.x + parent->curve.end.x)),
|
||||||
|
(1-count)*((1-count)*((1-count)*parent->curve.start.y + count * parent->curve.c0.y) + count *
|
||||||
|
((1-count)*parent->curve.c0.y + count*parent->curve.c1.y)) +
|
||||||
|
count *((1-count)*((1-count)*parent->curve.c0.y + count * parent->curve.c1.y) +
|
||||||
|
count * ((1-count)*parent->curve.c1.y + parent->curve.end.y)),
|
||||||
|
};
|
||||||
|
branch.startPos.x = dpos.x += parent->startPos.x;
|
||||||
|
branch.startPos.y = dpos.y += parent->startPos.y*1;
|
||||||
|
branch.cell.background = TART_COLOR_BRIGHT_CYAN_FOREGROUND;
|
||||||
|
return branch;
|
||||||
|
}
|
||||||
|
branch.cell = NULL_CELL;
|
||||||
|
branch.startPos.x = term_current_size().x/2.f;
|
||||||
|
branch.startPos.y = term_current_size().y/2.f;
|
||||||
|
return branch;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Draw Branch
|
* Draw Branch
|
||||||
*/
|
*/
|
||||||
void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) {
|
void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) {
|
||||||
struct tart_cell cell = NULL_CELL;
|
|
||||||
cell.display = '*';
|
|
||||||
struct nomiSpirel spirel;
|
struct nomiSpirel spirel;
|
||||||
nomi_curve c;
|
nomi_curve c;
|
||||||
int SizeOfFile = 600;
|
int SizeOfFile = 600;
|
||||||
char cellChart[] = {'%','*','\\','/','l','&','7','+','=','^',':'};
|
char cellChart[] = {'%','*','\\','/','l','&','7','+','=','^',':'};
|
||||||
unsigned int iderations = 0;
|
unsigned int iderations = 0;
|
||||||
|
|
||||||
if(branch->curve.start.x == 0) {
|
//if(branch->curve.start.x == 0) {
|
||||||
branch->curve.start = (nomi_vec2){
|
//branch->curve.start = (nomi_vec2){
|
||||||
0,
|
// 0,
|
||||||
0};
|
// 0};
|
||||||
branch->curve.c0 = (nomi_vec2){
|
//branch->curve.c0 = (nomi_vec2){
|
||||||
(( 25) * -1),
|
// (( 25) * -1),
|
||||||
((35/2.f) * -1)}; // controle point 0
|
// ((35/2.f) * -1)}; // controle point 0
|
||||||
branch->curve.c1 = (nomi_vec2){
|
//branch->curve.c1 = (nomi_vec2){
|
||||||
(( -10) * -1),
|
// (( -10) * -1),
|
||||||
((35/2.f) * -1)}; // controle point 1
|
// ((35/2.f) * -1)}; // controle point 1
|
||||||
branch->curve.end = (nomi_vec2){
|
//branch->curve.end = (nomi_vec2){
|
||||||
(( 3) * -1),
|
// (( 3) * -1),
|
||||||
((20/2.f) * -1)};
|
// ((20/2.f) * -1)};
|
||||||
c = RotateCurve(branch->curve, (nomi_vec2){0,0});
|
////c = RotateCurve(branch->curve, (nomi_vec2){0,0});
|
||||||
}
|
//}
|
||||||
|
|
||||||
struct tart_vec2 dpos = {0,0};
|
struct tart_vec2 dpos = {0,0};
|
||||||
float count = 0;
|
float count = 0;
|
||||||
@@ -110,22 +149,22 @@ void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) {
|
|||||||
iderations++;
|
iderations++;
|
||||||
|
|
||||||
|
|
||||||
cell.display = cellChart[rand_r(&iderations)%11];
|
branch->cell.display = cellChart[rand_r(&iderations)%11];
|
||||||
|
|
||||||
dpos = (struct tart_vec2){
|
dpos = (struct tart_vec2){
|
||||||
(1-count)*((1-count)*((1-count)*c.start.x + count * c.c0.x) +
|
(1-count)*((1-count)*((1-count)*branch->curve.start.x + count * branch->curve.c0.x) +
|
||||||
count * ((1-count)*c.c0.x + count*c.c1.x)) +
|
count * ((1-count)*branch->curve.c0.x + count*branch->curve.c1.x)) +
|
||||||
count * ((1-count)*((1-count)*c.c0.x + count * c.c1.x) +
|
count * ((1-count)*((1-count)*branch->curve.c0.x + count * branch->curve.c1.x) +
|
||||||
count * ((1-count)*c.c1.x + c.end.x)),
|
count * ((1-count)*branch->curve.c1.x + branch->curve.end.x)),
|
||||||
(1-count)*((1-count)*((1-count)*c.start.y + count * c.c0.y) + count *
|
(1-count)*((1-count)*((1-count)*branch->curve.start.y + count * branch->curve.c0.y) + count *
|
||||||
((1-count)*c.c0.y + count*c.c1.y)) +
|
((1-count)*branch->curve.c0.y + count*branch->curve.c1.y)) +
|
||||||
count *((1-count)*((1-count)*c.c0.y + count * c.c1.y) +
|
count *((1-count)*((1-count)*branch->curve.c0.y + count * branch->curve.c1.y) +
|
||||||
count * ((1-count)*c.c1.y + c.end.y)),
|
count * ((1-count)*branch->curve.c1.y + branch->curve.end.y)),
|
||||||
};
|
};
|
||||||
dpos.x += branch->startPos.x;
|
dpos.x += branch->startPos.x;
|
||||||
dpos.y += branch->startPos.y;
|
dpos.y += branch->startPos.y;
|
||||||
if(dpos.x >= 0 && dpos.y >=0) {
|
if(dpos.x >= 0 && dpos.y >=0) {
|
||||||
tart_draw_cell_position(tart_get_buffer(w, b), cell, dpos);
|
tart_draw_cell_position(tart_get_buffer(w, b), branch->cell, dpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char* text; // This is the data that is in that branch
|
char* text; // This is the data that is in that branch
|
||||||
branchId children[MAX_CHILDREN]; // holds the branchIds of its children
|
branchId children[MAX_CHILDREN]; // holds the branchIds of its children
|
||||||
|
struct tart_cell cell;
|
||||||
void* parent; // points the the branches parent
|
void* parent; // points the the branches parent
|
||||||
char type; // holds the type as in if this struct is a branch or a trunk
|
char type; // holds the type as in if this struct is a branch or a trunk
|
||||||
nomi_vec2 startPos; // the starting position of the branch
|
nomi_vec2 startPos; // the starting position of the branch
|
||||||
@@ -74,6 +75,7 @@ void CreaetBranch(trunk* trunk);
|
|||||||
* */
|
* */
|
||||||
branch* LocateBranch();
|
branch* LocateBranch();
|
||||||
|
|
||||||
|
branch create_branch(branch* parent, nomi_vec2 d);
|
||||||
/*
|
/*
|
||||||
* Draw Branch
|
* Draw Branch
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user