diff options
Diffstat (limited to 'demo/wsim.c')
-rw-r--r-- | demo/wsim.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/demo/wsim.c b/demo/wsim.c new file mode 100644 index 0000000..78fdf77 --- /dev/null +++ b/demo/wsim.c @@ -0,0 +1,168 @@ +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include "cbrll.h" +/* map holding the pixels for a 200x200 pixel imagebuffer, [x][y] + * bits are in braille order within each byte + */ +uint8_t map[100][50]; +/* takes char storing the on/off positions of 8 points, in braille encoding + * order, and prints the corresponding braille char + */ + +/* global state bit switch */ +uint8_t state = 3; +#define STATE_LOOP 0x01 +#define STATE_DEJURE 0x02 + + +/*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); + /*seeds random*/ + srand(696969); + for (int i = 0; i < 64; i++) { + nodes[i] = makenode(); + } + while (state & STATE_LOOP) { + for (int i = 1; i < 64; i++) { + drawnode(nodes[i]); + } + drawnode(nodes[0]); + printmap(0, 100, 0, 50); + + + /* checks input*/ + input = getc(stdin); + /*haven't set the terminal to raw mode so will still need + * space + */ + if (input == 'q') { + state = state & (~STATE_LOOP); + } + } + return 0; +} |