Whilst messing about with my own programming language, I've been getting it to display output in the browser, which all looks very retro because it's text only.
So I decided that it would be nice to prettify things a little bit, without going to very much trouble. It would also be nice to be able to do things like clear the screen, or move the cursor around. But I didn't want to invent my own protocol, I thought that it would be much better to just use an existing thing.
For that reason, I thought it might be handy just to use ANSI escape sequences. Whilst that would still look all very retro (use of these codes goes way back to the 1970s), it would bring some new capabilities to the table, like colour and very simple graphics. It should even allow very basic animations. Of course, this isn't what I have designed H2D2 for; but it's a nice way to test the language.
But with my version, it doesn't matter where the output comes from, the code just deals with drawing it onto the page. It means that the library can deal with any text containing ANSI escape codes. It even allows more than one 'console' to appear on the same webpage. I have also included support for extended colour codes, meaning that RGB values can be used. It's possible to turn scrolling on or off, and you can keep appending more text when you like.
Anyway, it worked a treat when I plugged it back into my H2D2 demo. Here's some hurriedly hacked together example output:
For a long time I've been aware of Ncurses,
but I've never actually used it. So when I accidentally wandered across
tutorial for using Ncurses in Xcode, I decided that it would be worth checking out.
But, when I found myself with a few spare minutes... I was sitting in front of a machine
running Debian Linux rather than Mac OS X. So I experimented there instead. To get the
snakey program to run I
had to do the following:
- First of all, I had to get the ncurses stuff:
sudo apt-get install libncurses5-dev
- Then I had to compile the example code (I had renamed the program to box.c):
gcc box.c -lncurses -o box
- Then finally, I could run it:
So that was pretty easy. Ncurses is one of those things that I'd like to mess about
with some more, because I still like running stuff in a console window.
Since my school days, I've always liked the Game
of Life, invented by mathematician John Conway. It
nicely demonstrates how complex behaviour can come about from just a few simple rules.
Anyway, when I was reading up on the I2C interface recently,
I accidentally found
this code on the Wiring Pi
website (which is a GPIO interface library for the Raspberry Pi). It looked like a nicely written bit of code
so I decided to write something similar in C#. There's no real reason why I should, but it just seemed like
a fun thing to do...
In terms of my example (with black and white cells), the rules go like this:
- a black cell with less than 2 black neighbours goes white
- a black cell with 2 or 3 black neighbours stays the same
- a black cell with more than 3 black neighbours goes white
- a white cell with three black neighbours becomes black
Here is the result:
This console app version demonstrates a glider
gun, which is some pretty impressive behaviour from those four simple rules.
Oh, and if you're really interested, and would like to see my code, it's here (as a text file).