316 lines
8.6 KiB
C
316 lines
8.6 KiB
C
#include <string.h>
|
|
#include <tart.h>
|
|
#include <math.h>
|
|
#include "nomi.h"
|
|
#include <stdlib.h>
|
|
|
|
#define SPIREL_MOD 0.618055f
|
|
|
|
#define NOMAI_END_OF_THOUGHT(id) <*ID:#id/>
|
|
#define NOMAI_MARKERS_TO_STRING(marker) #marker
|
|
|
|
|
|
struct nomiSpirel {
|
|
struct tart_cell selected_cell;
|
|
struct tart_cell unselected_cell;
|
|
struct tart_vec2 startPos;
|
|
struct tart_vec2 size;
|
|
struct tart_vec2 endPos;
|
|
unsigned char oreantation;
|
|
int fibonacci[3];
|
|
};
|
|
|
|
struct nomiMenu {
|
|
struct nomiSpirel branches[MAX_BRANCHES];
|
|
struct tart_vec2 startPos;
|
|
struct tart_vec2 size;
|
|
struct tart_vec2 origin;
|
|
unsigned char brachIds[MAX_BRANCHES];
|
|
};
|
|
|
|
struct nomiNavigation {
|
|
branchId branches[30]; // this list of the traveld branches.
|
|
unsigned char depth; // The current depth is the id of the selected branch.
|
|
branch* selectedBranch;
|
|
};
|
|
|
|
struct nomiNavigation __nav__ = {
|
|
.branches = {0},
|
|
.depth = 0,
|
|
};
|
|
|
|
/*
|
|
* This will Init Nomi
|
|
*/
|
|
void NomiInit(trunk* tr) {
|
|
__nav__ = (struct nomiNavigation){ .branches = {0}, .depth = 0, .selectedBranch = &tr->branches[0] };
|
|
__nav__.branches[0] = 1;
|
|
__nav__.depth = 1;
|
|
}
|
|
|
|
branchId* NomiNavigation(char input) {
|
|
|
|
switch(input) {
|
|
case '1':
|
|
__nav__.branches[__nav__.depth] = 1;
|
|
__nav__.depth++;
|
|
break;
|
|
case '2':
|
|
__nav__.branches[__nav__.depth] = 2;
|
|
__nav__.depth++;
|
|
break;
|
|
case '3':
|
|
__nav__.branches[__nav__.depth] = 3;
|
|
__nav__.depth++;
|
|
break;
|
|
case '0':
|
|
if(__nav__.depth > 0) {
|
|
__nav__.branches[__nav__.depth] = 0;
|
|
__nav__.depth--;
|
|
__nav__.branches[__nav__.depth] = 0;
|
|
}
|
|
break;
|
|
}
|
|
return __nav__.branches;
|
|
}
|
|
|
|
branch* GetSelectedBranch() {
|
|
return __nav__.selectedBranch;
|
|
}
|
|
void SetSelectedBranch(branch* b) {
|
|
__nav__.selectedBranch = b;
|
|
}
|
|
|
|
/*
|
|
* This will create the truk of the note.
|
|
* */
|
|
trunk CreateTrunk(char* title, branch root) {
|
|
trunk t = {
|
|
.title = title,
|
|
.branchCount = 1,
|
|
.branches = {0},
|
|
.text = 0,
|
|
};
|
|
t.branches[0] = root;
|
|
return t;
|
|
}
|
|
|
|
void DrawTrunk(trunk *tr, struct tart_window* w, tart_byte b) {
|
|
unsigned int f = 30;
|
|
for(int i = 0; i < tr->branchCount; i++) {
|
|
DrawBranch(&tr->branches[i], 100, w, b);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This is a test
|
|
* */
|
|
void AddBranch(trunk* t, branch br) {
|
|
if(t->branchCount < MAX_BRANCHES) {
|
|
t->branches[t->branchCount] = br;
|
|
t->branchCount++;
|
|
__nav__.selectedBranch = &t->branches[t->branchCount];
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
* Locate Branch
|
|
* */
|
|
branchId* LocateBranch(trunk* t) {
|
|
char found = 1;
|
|
for(int i = 0; i < t->branchCount; i++) {
|
|
found = 1;
|
|
for(int idIdx = 0; idIdx < 30; idIdx++) {
|
|
if(t->branches[i].navId[idIdx] != __nav__.branches[idIdx]){
|
|
found = 0;
|
|
|
|
}
|
|
|
|
}
|
|
if(found == 1) {
|
|
__nav__.selectedBranch->cell.background = TART_COLOR_GREEN_FOREGROUND;
|
|
__nav__.selectedBranch = &t->branches[i];
|
|
__nav__.selectedBranch->cell.background = TART_COLOR_WHITE_FOREGROUND;
|
|
}
|
|
}
|
|
return __nav__.selectedBranch->navId;
|
|
}
|
|
|
|
float t = 0;
|
|
|
|
|
|
float a = 0;
|
|
nomi_vec2 RotatePoint(nomi_vec2 or,nomi_vec2 t, nomi_vec2 d) {
|
|
nomi_vec2 pos;
|
|
|
|
float c = atan2(d.y, d.x) - 3.14f/2;
|
|
//a+= 0.0002f;
|
|
pos.x = (t.x * cos(a+c) - t.y * sin(a+c));
|
|
pos.y = (t.x * sin(a+c) + t.y * cos(a+c))/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;
|
|
}
|
|
|
|
/*
|
|
* create_branch
|
|
*
|
|
* branch* parent: this is the parent that this branch is connected to.
|
|
* nomi_vec2 d: This is the direction within the vector.
|
|
*/
|
|
|
|
branch create_branch(branch* parent, nomi_vec2 d, unsigned char percent,
|
|
unsigned char b) {
|
|
branch br = {
|
|
.navId = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
|
|
.childrenCount = 0,
|
|
.parent = parent
|
|
};
|
|
|
|
br.curve.start = (nomi_vec2){
|
|
0,
|
|
0};
|
|
br.curve.c0 = (nomi_vec2){
|
|
(( 25) * -1),
|
|
((35/2.f) * -1)}; // controle point 0
|
|
br.curve.c1 = (nomi_vec2){
|
|
(( -10) * -1),
|
|
((35/2.f) * -1)}; // controle point 1
|
|
br.curve.end = (nomi_vec2){
|
|
(( 3) * -1),
|
|
((20/2.f) * -1)};
|
|
br.curve = RotateCurve(br.curve, d);
|
|
|
|
branch* p = parent;
|
|
branchId tmpId[MAX_BRANCHES] = {1};
|
|
int depth = 1;
|
|
br.id = 1;
|
|
if (parent != NULL) {
|
|
|
|
parent->childrenCount++;
|
|
br.id = parent->childrenCount;
|
|
tmpId[0] = br.id;
|
|
|
|
for(int i = 1; i < MAX_BRANCHES; i++) {
|
|
tmpId[i] = p->id;
|
|
depth = i+1;
|
|
if(p->parent != NULL) {
|
|
p = p->parent;
|
|
}else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
for(int i = 0; i < depth; i++) {
|
|
br.navId[i] = tmpId[depth-1 - i];
|
|
}
|
|
}else {
|
|
depth = 0;
|
|
br.navId[0] = 1;
|
|
br.id = 1;
|
|
}
|
|
br.depth = depth;
|
|
|
|
|
|
|
|
if(parent != NULL) {
|
|
float count = percent/100.f;
|
|
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)),
|
|
};
|
|
br.startPos.x = dpos.x += parent->startPos.x;
|
|
br.startPos.y = dpos.y += parent->startPos.y*1;
|
|
br.cell = NULL_CELL;
|
|
br.cell.background = b;
|
|
return br;
|
|
}
|
|
br.cell = NULL_CELL;
|
|
br.cell.background = b;
|
|
br.startPos.x = term_current_size().x/2.f;
|
|
br.startPos.y = term_current_size().y/2.f;
|
|
return br;
|
|
}
|
|
|
|
/*
|
|
* Draw Branch
|
|
*
|
|
* *branch* branch*: this is the branch that would be rendered.
|
|
* *unsigned char* p*: this is the persentage.
|
|
* *struct tart_window* w*: this is the window that will be rendered.
|
|
* *tart_byte b*: this is the selected buffer.
|
|
*/
|
|
void DrawBranch(branch* branch, unsigned char p, struct tart_window* w, tart_byte b) {
|
|
// List of random chars to be renderd
|
|
char cellChart[] = {'0','1','2','3','l','&','7','+','=','^',':'};
|
|
unsigned int iderations = 0;
|
|
|
|
|
|
struct tart_vec2 dpos = {0,0};
|
|
float count = 0;
|
|
|
|
while(count < p/100.0) {
|
|
|
|
|
|
iderations++; // for selecting a random char to be renderd
|
|
|
|
|
|
//branch->cell.display = cellChart[rand_r(&iderations)%11];
|
|
if(branch->id > 0 && branch->id < 11) {
|
|
branch->cell.display = cellChart[branch->id];
|
|
}else {
|
|
branch->cell.display = cellChart[10];
|
|
}
|
|
|
|
dpos = (struct tart_vec2){
|
|
(1-count)*((1-count)*((1-count)*branch->curve.start.x + count * branch->curve.c0.x) +
|
|
count * ((1-count)*branch->curve.c0.x + count*branch->curve.c1.x)) +
|
|
count * ((1-count)*((1-count)*branch->curve.c0.x + count * branch->curve.c1.x) +
|
|
count * ((1-count)*branch->curve.c1.x + branch->curve.end.x)),
|
|
(1-count)*((1-count)*((1-count)*branch->curve.start.y + count * branch->curve.c0.y) + count *
|
|
((1-count)*branch->curve.c0.y + count*branch->curve.c1.y)) +
|
|
count *((1-count)*((1-count)*branch->curve.c0.y + count * branch->curve.c1.y) +
|
|
count * ((1-count)*branch->curve.c1.y + branch->curve.end.y)),
|
|
};
|
|
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), branch->cell, dpos);
|
|
}
|
|
|
|
count += .01f;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Create Nomi File
|
|
*
|
|
* name: the name of the file that will be created.
|
|
*/
|
|
FILE CreateNomiFile(const char* name);
|
|
|
|
/*
|
|
* Save Nomi File
|
|
*
|
|
* file: the pointer to the nomi file.
|
|
*/
|
|
void SaveNomiFile(FILE* file);
|