Old school output on the web

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.

What I have ended up with is a JavaScript library which renders ANSI escape sequences onto a webpage. I was able to get a very good head start by using the existing code in escapes.js.

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:

As you can see, all I have done is taken my existing sphere drawing program and gotten it to output ANSI escape codes rather than plain text characters. When I get some time, I'll probably put the JavaScript library on GitHub.

Phone upgrade: Motorola G (4G)

I've had my iPhone for quite a few years now. It's an iPhone 3GS and for a long time I have not had a compelling reason to change it. But these days I find myself stuck on iOS 6 when lots of Apps now require iOS 7 or later. So I'm getting left out in the cold. It's time to do something about that.

But on the old iPhone I also can't do things like set up a personal wifi hotspot. I can do connection sharing over bluetooth or by a cable, but I find that type of connection is not well supported on non-Apple devices. So I can't use the internet access from my phone on my Andriod tablet (although it works fine with the iPad).

The old iPhone does seem slower than it used to, so getting a new phone with a faster processor would be good too. And it will also be nice to get a better camera. So I've decided to try out one of these phones: Motorola G (the 4G version).

I like the idea of the SD card slot for extra storage and for the price it seems a very good spec. It's a shame there is no way to connect an HDMI cable, but I can live without that. But I was finding it hard to justify the cost of another Apple phone, when I've been quite satisfied with the Android OS recently. I used to feel that the Apple phones were better quality (both in terms of hardware and software). But things have moved on.

After a few days of use, I am very impressed with the Moto G. The only problem I have found so far is with the Android KitKat OS itself. There is a serious bug with the stock e-mail App which has now gone unfixed for nearly a year. That's pretty bad. I'm surprised to see it classified as Priority: small when the effect is that e-mails are deleted from the server when you have told it not to.

So I cannot use the standard e-mail App, and at the moment I'll use the K-9 App instead. It's a shame, because in previous releases of Android the e-mail App was working fine. Even so, I am pretty happy with my choice of phone. I've even started reading some pages on Android development - although it was mainly out of idle curiosity. But you never know...

Drawing spheres with H2D2

Since I wrote this blog post, I have been looking for a better demo program to show what I can do with my H2D2 programming language. I needed something more interesting than "hello world" ... and which didn't involve drawing the Mandelbrot set.

I started trawling through the Rosetta Code website for inspiration and came across this sphere drawing program in C. I guess it's a simple ray tracing algorithm really. It seemed like a reasonable candidate.

So I set about porting it from C to H2D2, which was an interesting experience. Interesting because H2D2 is not very forgiving when you make mistakes - since I have not (yet) made the compiler error messages very user friendly. So it makes you reason things out very carefully in your head, rather than rely on the compiler to spot problems with your code.

I have managed to get it to work though, and the resulting H2D2 example program shows a few of the language features (like a function call and arrays for example). However, it also highlights a few things I should work on, like creating a syntactic shortcut for assigning values to an array. Anyway, I can now create output like this:

             !!...!!!***Bo               
         ..............!!**Boo           
      ..................!!**BBooe        
    .....................!!**BBooee      
   .......................!!**BBooee     
  ........................!!**BBoooee    
 .........................!!**BBoooeee   
!........................!!***BBoooeeee  
........................!!***BBooooeeee  
!......................!!***BBBoooeeeee  
!....................!!!***BBBoooeeeeeo  
*!.................!!!***BBBBoooeeeeeeo  
B*!!!...........!!!!****BBBooooeeeeeeoB  
 B***!!!!!!!!!!!*****BBBBoooooeeeeeeoo   
  oBB*************BBBBBoooooeeeeeeeoo    
   ooBBBBBBBBBBBBBBooooooeeeeeeeeooB     
    eoooooooooooooooooeeeeeeeeeooo*      
      eeeooooooooeeeeeeeeeeeeooB*        
         eeeeeeeeeeeeeeeeeoooB           
             oeeeeeeooooBB

But to show it in action, I made this recording, which shows it off in realtime in the browser:

Anyway, I am really pleased that it works so well. I can go back to fiddling around with the language now.