Gilles of all trades

Personal journey across software development, web trends, photography and life.


Oldies 2000: metaballs

October 8th, 2008 by Gilles

Boy was I glad to remember that Dosbox can be used to run old Turbo Pascal programs! It makes me so nostalgic to see this running, and a bit sad to have lost the older things I had written in Pascal.

I was an assembly freak at the time and I remember being very proud of the routine below, which was used to render circles (not used in metaK as far as I know, but metaballs did rely heavily on that mode 13h library I wrote). I wrote the routine and the library from scratch using a text file describing the specifications of that VGA mode.

I remember that I first based the circle routine on mathematical rules and then identified sections that could be optimized to run faster. Today I can’t understand much in that code. If blogs existed at the time I’m sure I would have written a few posts about the techniques used to write and optimize that assembly library.

The library could load images, render all sorts of shapes, text, all these routine written in assembly for performance. I even remember that at some stage I had made a program that would display molecules in 3D with a homemade 3D engine based on that same mode 13h library. I think this program has been lost unfortunately.

For your personal enjoyment, you can download the executable and source code of that gem. You’ll need DosBox to run it though, as well as the knowledge of how to use DOS!.

Procedure Circle(x,y,r: integer);assembler; { Cercle... } Var y1,y2,x1,x2,i,r2: integer; Asm mov cx,x { Ma version du tracÇ de cercle, me semble plutìt rapide, } sub cx,r { mais je n'ai pas cherchÇ Ö l'amÇliorer. } @boucle: mov ax,cx sub ax,x mul ax mov bx,ax mov ax,r mul ax sub ax,bx { ax= r˝ - (i-x)˝ } mov r2,ax mov ax,0 mov bx,ax @racine: mov ax,bx inc ax mov bx,ax mul ax cmp ax,r2 jl @racine mov ax,bx mov bx,y sub bx,ax add ax,y { ax= y+sqrt(r˝- (i-x)˝ } { bx= y-sqrt(r˝- (i-x)˝ } push ax les di,_buffer mov ax,320 mul bx add ax,cx add di,ax mov al,_couleur mov es:[di],al pop ax mov bx,ax les di,_buffer mov ax,320 mul bx add ax,cx add di,ax mov al,_couleur mov es:[di],al mov ax,x add ax,r add cx,1 cmp cx,ax jne @boucle mov cx,y sub cx,r @boucle2: mov ax,cx sub ax,y mul ax mov bx,ax mov ax,r mul ax sub ax,bx { ax= r˝ - (i-y)˝ } mov r2,ax mov ax,0 mov bx,ax @racine2: mov ax,bx inc ax mov bx,ax mul ax cmp ax,r2 jl @racine2 mov ax,bx mov bx,x sub bx,ax add ax,x { ax= x+sqrt(r˝- (i-y)˝ } { bx= y-sqrt(r˝- (i-y)˝ } cmp _style,0 je @s0 inc ax cmp _style,1 je @s1 @s0: push ax les di,_buffer mov ax,320 mul cx add ax,bx add di,ax mov al,_couleur mov es:[di],al pop ax mov bx,ax les di,_buffer mov ax,320 mul cx add ax,bx add di,ax mov al,_couleur mov es:[di],al jmp @fin @s1: push ax les di,_buffer mov ax,320 mul cx add ax,bx add di,ax mov al,_couleur mov es:[di],al pop ax inc bx cmp bx,ax jne @s1 jmp @fin @fin: mov ax,y add ax,r add cx,1 cmp cx,ax jne @boucle2 End;

Javascript wizardry: automatically save changes upon shutdown

October 4th, 2008 by Gilles

It seems like every week I learn something new about what javascript can do. I’ve been looking through javascript questions on stackoverflow, hunting for new tricks to add to my bag. Today I’ve discovered the power of window.onbeforeunload.

It allows you to call some javascript code just before the tab or browser is closed. It’s generally used to display one of those popups that annoy the hell out of me:

Google and the other web services who use it should know better, popups are bad UI. The reason why GMail has this popup is to warn you that the draft you’re writing is not saved. The most annoying occurrence of that popup message is when you’re trying to shut down your browser or computer. 99% of the time when I shut down the browser I know that these changes will be lost and the popup is just a really pain, stopping me halfway through the simple task I want to do.

So while playing with onbeforeunload today I’ve discovered that there’s probably a better way (TM). The main purpose of the popup is to remind you that you’re about to lose some data by shutting down your browser. Why not just be quiet and save it then? An SJAX request can be done very easily (it’s like AJAX, expect synchronous) and then you’re done. Here’s a quick example using prototype:

window.onbeforeunload = shutDown; function shutDown() { new Ajax.Request("updatename.php", { parameters: { name: $F("name") }, asynchronous: false }); }

I’ve just implemented it in my current project (see video below) to allow the preferences page to be always up to date, even if users decide to navigate away, close their browser or whatever before the AJAX request has had time to be triggered and processed. The result is an OS X-like system where you never have to press save in a preferences panel, even if you shut it down immediately after making a change.

The only drawback of that technique is that you need to make sure that the SJAX request is fast. You can’t afford to automatically save upon shutdown if you know that the request will take several seconds to process. This would be become almost as annoying as the popup. So you might want to balance both (auto-save and popup) depending on how time-consuming the request is going to be. However, since not allowing any request on my website to take more than a second to process is one of the main target of my design, I’ll most likely use this trick wherever it makes sense to.

Popups are dead, long lives auto-save upon shutdown!

Oldies 2000: CQCB

October 1st, 2008 by Gilles

I’ve been reorganizing all my archives by year and I thought I might share the sometimes laughable small or big projects I was up to many years ago. The first one presented here is called “CQCB” made in June 2000 and only its very poor texture can top its utter lack of purpose.

Note that the choppy framerate is only due to the poor screencasting software I’m using.

It’s basically an OpenGL rotating cube. The arrow keys are used to increase its rotational speed. It blinks, which must have been quite a breakthrough compared to earlier versions which have not remained in my archives.

The text on the cube is the name of a radio show I was listening to at the time, which probably went the way of the dodo.

I’m pretty sure that I used the NeHe tutorials to learn how to do this (which by the way starts teaching you OpenGL with… cubes).

Sadly CQCB’s source code is gone, it seems like I judged at the time that perfection had been reached and there was no need to keep the source code for further modification.

If you feel in the need for some pointless cubeness, CQCB is available right here.

« Previous Entries