From 703207efa6149cf98256868634994be48d5497bd Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Thu, 22 Feb 2018 13:08:28 -0500 Subject: added nodes --- wsim.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 134 insertions(+), 8 deletions(-) diff --git a/wsim.c b/wsim.c index cfaa089..1aa8095 100644 --- a/wsim.c +++ b/wsim.c @@ -1,6 +1,7 @@ #include #include #include +#include /* map holding the pixels for a 200x200 pixel imagebuffer, [x][y] * bits are in braille order within each byte */ @@ -10,8 +11,10 @@ uint8_t map[100][50]; */ /* global state bit switch */ -uint8_t state = 1; +uint8_t state = 3; #define STATE_LOOP 0x01 +#define STATE_DEJURE 0x02 + void printbraille(uint8_t points) { /* outputs braille characters, the encoding for braile is: * 1 4 @@ -188,20 +191,143 @@ void drawline(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t dot) { return; } +/*node, the thing being simulated + * 16 bytes each + */ +struct node { + /*culture to compare similatiry*/ + uint8_t culture; + /*strength to spread culture*/ + uint8_t memetic; + /*strength martial*/ + uint8_t martial; + /*state allegiance*/ + uint8_t dejure; + /*x and y positions*/ + uint8_t x; + uint8_t y; + /*connections to other nodes, 0 represents none*/ + uint8_t connections[10]; +}; +/*all the nodes, 0 is not used*/ +struct node nodes[256]; +/*makes a new random node*/ +struct node makenode() { + /*node to work on*/ + struct node rnode; + rnode.culture = (uint8_t)rand(); + rnode.memetic = (uint8_t)rand(); + rnode.martial = (uint8_t)rand(); + rnode.dejure = (uint8_t)rand(); + rnode.x = (uint8_t)rand(); + while (rnode.x >= 200) { + rnode.x = (uint8_t)rand(); + } + rnode.y = (uint8_t)rand(); + while (rnode.y >= 200) { + rnode.y = (uint8_t)rand(); + } + memset(rnode.connections, 0, 10*sizeof(uint8_t)); + return rnode; +} +/*draws nodes based on dejure or culture*/ +void drawnode(struct node drawn) { + /*which symbol to draw*/ + uint8_t symbol; + if (state & STATE_DEJURE) { + symbol = drawn.dejure; + } else { + symbol = drawn.culture; + } + /* draws symbol*/ + /*layout as follows + * 012 + * 7X3 + * 654 + */ + setpixel(drawn.x, drawn.y, 1); + setpixel(drawn.x-1, drawn.y-1, (symbol & (0x01 << 0)) && 1); + setpixel(drawn.x, drawn.y-1, (symbol & (0x01 << 1)) && 1); + setpixel(drawn.x+1, drawn.y-1, (symbol & (0x01 << 2)) && 1); + setpixel(drawn.x+1, drawn.y, (symbol & (0x01 << 3)) && 1); + setpixel(drawn.x+1, drawn.y+1, (symbol & (0x01 << 4)) && 1); + setpixel(drawn.x, drawn.y+1, (symbol & (0x01 << 5)) && 1); + setpixel(drawn.x-1, drawn.y+1, (symbol & (0x01 << 6)) && 1); + setpixel(drawn.x-1, drawn.y, (symbol & (0x01 << 7)) && 1); + /*draws memetic strenth*/ + /*Ma + *00123 Me + *1XXX4 + *2XOX5 + *3XXX6 + *45677 + */ + //a swich without breaks keeps executing + switch (drawn.memetic / 32) { + case 7: + setpixel(drawn.x+2,drawn.y+2,1); + case 6: + setpixel(drawn.x+2,drawn.y+1,1); + case 5: + setpixel(drawn.x+2,drawn.y,1); + case 4: + setpixel(drawn.x+2,drawn.y-1,1); + case 3: + setpixel(drawn.x+2,drawn.y-2,1); + case 2: + setpixel(drawn.x+1,drawn.y-2,1); + case 1: + setpixel(drawn.x,drawn.y-2,1); + case 0: + setpixel(drawn.x-1,drawn.y-2,1); + } + //martial strenth + switch (drawn.martial / 32) { + case 7: + setpixel(drawn.x+1,drawn.y+2,1); + case 6: + setpixel(drawn.x,drawn.y+2,1); + case 5: + setpixel(drawn.x-1,drawn.y+2,1); + case 4: + setpixel(drawn.x-2,drawn.y+2,1); + case 3: + setpixel(drawn.x-2,drawn.y+1,1); + case 2: + setpixel(drawn.x-2,drawn.y,1); + case 1: + setpixel(drawn.x-2,drawn.y-1,1); + case 0: + setpixel(drawn.x-2,drawn.y-2,1); + } + //draws connections + for (uint8_t i = 0; i < 10; i++) { + if (drawn.connections[i] != 0) { + drawline(drawn.x, drawn.y, + nodes[drawn.connections[i]].x, + nodes[drawn.connections[i]].y, + 1); + } + } +} + int main (int argc, char * argv[]) { /*holds keypress*/ char input; /*zeroing map*/ memset(map, 0, sizeof(map[0][0]) * 100 * 50); - printmap(); + /*seeds random*/ + srand(696969); + for (int i = 0; i < 64; i++) { + nodes[i] = makenode(); + } while (state & STATE_LOOP) { - setpixel(10,20,2); - drawline(0,0,20,20,1); - drawline(0,40,10,20,1); - drawline(10,50,0,40,2); - drawline(10,0,10,200,1); - drawline(10,100,100,100,4); + for (int i = 1; i < 64; i++) { + drawnode(nodes[i]); + } + drawnode(nodes[0]); printmap(); + /* checks input*/ input = getc(stdin); -- cgit v1.1