Close

'maze'

A project log for Random Ridiculosities and Experiments

Sometimes yah's just gots tah try somethin', regardless of whether it'll become a full-fledged "project"...

eric-hertzEric Hertz 01/24/2017 at 12:592 Comments

UPDATE: Hah! It's even easier than that! See bottom...

----------------

Had no idea how easy it is to create a maze... This looks great on low-resolution.

@matseng has a brilliant looking one in only 64x32 pixels over at #Tjipp8 - A Chip-8 game console

https://hackaday.io/project/19483-tjipp8-a-chip-8-game-console/log/52343-chip-8-interpreter-is-working/

Here it is in C... (not even remotely as efficiently-implemented!)

#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h> //random

char bitmaps[2][4][5] = {{ "\\   " ,
                           " \\  " ,
                           "  \\ " ,
                           "   \\" },

                         { "  / " ,
                           " /  " ,
                           "/   " ,
                           "   /" }};


uint8_t lineBuffer[80/4];

int main(void)
{
   uint8_t row, col;

   for(row=0; row<24; row++)
   {

      for(col=0; col<80/4; col++)
      {
         if(row%4 == 0)
         {
            lineBuffer[col] = (rand() & 0x01);
         }

         printf("%s", bitmaps[lineBuffer[col]][row%4]);
      }
      printf("\n");
   }
   return 0;
}

--------------------

Apparently the original program was a "classic" one-liner in Basic, that somehow seemed to slip through my experience until now...

Reimplemented in C, it's essentially nothing more than:

while (1) { printf("%c", (rand()&0x1) ? '\\' : '/' ); }
The earlier was coded-up from matseng's code-example which was designed for a system in graphics-mode, rather than character-mode. I guess what I've done, then, is re-implement the character-bitmaps with sub-characters... hahaha.

Seriously, check out his log. There's a link to a *really short* code-routine in "Bit8" which looks a bit like assembly, and a link to a book that's all about that one liner. An interesting read, it would seem.

https://hackaday.io/project/19483-tjipp8-a-chip-8-game-console/log/52343-chip-8-interpreter-is-working/

------------

As far as what I'd done, earlier... Reimplementing, essentially, a character with a block of characters, I guess it sorta "zooms in" on a line-drawing...

Here's the output from the one-liner:

(heh, note that the original I copied didn't have simply diagonals; for some reason one diagonal was vertically-shifted slightly... hmmm... kinda like the "dot" inside the boxes...)..

Discussions

matseng wrote 01/24/2017 at 18:13 point

Heh.... It seems like it works just as well in c as in chip-8 ;-)

I wonder if this can be classified as a "real" maze or if it's too simplisticly fake. It at least looks kinda real. Maybe it will be clearer if made with more "cells".

  Are you sure? yes | no

Eric Hertz wrote 01/24/2017 at 19:29 point

dunno, but it's a great demo for low-res graphics, and I got a lot of those looking for demos... :)

  Are you sure? yes | no