added nomi spirel
This commit is contained in:
165
source/nomi.c
165
source/nomi.c
@@ -0,0 +1,165 @@
|
||||
#include <tart.h>
|
||||
#include <math.h>
|
||||
#include "nomi.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SPIREL_MOD 0.618055f
|
||||
|
||||
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[30];
|
||||
struct tart_vec2 startPos;
|
||||
struct tart_vec2 size;
|
||||
struct tart_vec2 origin;
|
||||
unsigned char brachIds[30];
|
||||
};
|
||||
|
||||
/*
|
||||
* This will Init Nomi
|
||||
*/
|
||||
void NomiInit();
|
||||
/*
|
||||
* This will create the truk of the note.
|
||||
* */
|
||||
trunk* CreateTrunk();
|
||||
|
||||
/*
|
||||
* This is a test
|
||||
* */
|
||||
void CreaetBranch(trunk* trunk);
|
||||
|
||||
/*
|
||||
* Locate Branch
|
||||
* */
|
||||
branch* LocateBranch();
|
||||
|
||||
/*
|
||||
* Draw Branch
|
||||
*/
|
||||
void DrawBranch(branch* branch, struct tart_window* w, tart_byte b) {
|
||||
struct tart_cell cell = NULL_CELL;
|
||||
cell.display = '*';
|
||||
struct nomiSpirel spirel;
|
||||
int SizeOfFile = 210;
|
||||
char cellChart[] = {'%','*','\\','/','l','&','b','+','=','^',':'};
|
||||
int iderations = 0;
|
||||
int fib = 0;
|
||||
int fib1 = 1;
|
||||
int fib2 = 0;
|
||||
struct tart_vec2 pos = {40,10};
|
||||
struct tart_vec2 nextPos;
|
||||
unsigned int count = 0;
|
||||
|
||||
while(SizeOfFile/10 > fib) {
|
||||
|
||||
// This is the direction that the spirel is oreanted
|
||||
// 0 = up
|
||||
// 1 = left
|
||||
// 2 = down
|
||||
// 3 = right
|
||||
|
||||
if(iderations < 3){
|
||||
iderations++;
|
||||
} else {
|
||||
iderations = 0;
|
||||
}
|
||||
|
||||
fib = fib1 + fib2;
|
||||
fib2 = fib1;
|
||||
fib1 = fib;
|
||||
|
||||
|
||||
cell.display = cellChart[rand_r(&count)%11];
|
||||
|
||||
switch(iderations) {
|
||||
case 0: // up
|
||||
pos.x += fib/2;
|
||||
pos.y += fib/2;
|
||||
for(int i = 0; i < fib/2; i ++){
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x-(i-2), pos.y-i});
|
||||
count++;
|
||||
cell.display = cellChart[rand_r(&count)%11];
|
||||
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x-(i-2) + 1, pos.y-i});
|
||||
}
|
||||
break;
|
||||
case 1: // right
|
||||
pos.x += fib/2;
|
||||
pos.y -= fib/2;
|
||||
for(int i = 0; i < fib/2; i ++){
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x - i, pos.y+i});
|
||||
count++;
|
||||
cell.display = cellChart[rand_r(&count)%11];
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x-i + 1, pos.y+i});
|
||||
}
|
||||
break;
|
||||
case 2: // down
|
||||
pos.x -= fib/2;
|
||||
pos.y -= fib/2;
|
||||
for(int i = 0; i < fib/2; i ++){
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x+(i+2), pos.y+i});
|
||||
count++;
|
||||
cell.display = cellChart[rand_r(&count)%11];
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x+(i+2) + 1, pos.y+i});
|
||||
}
|
||||
break;
|
||||
case 3: // left
|
||||
pos.x -= fib/2;
|
||||
pos.y += fib/2;
|
||||
for(int i = 0; i < fib/2; i ++){
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x+i, pos.y-i});
|
||||
count++;
|
||||
cell.display = cellChart[rand_r(&count)%11];
|
||||
tart_draw_cell_position(tart_get_buffer(w, b),
|
||||
cell,
|
||||
(struct tart_vec2){pos.x+ i + 1, pos.y-i});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
//for(int i = 0; i < rint((SizeOfFile/10.0f)*SPIREL_MOD); i++) {
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
Reference in New Issue
Block a user