Jolie Rouge


all ur parentheses Я belong to me


Implementing cons, car, and cdr in Lua.

Lua is by far the best scripting language I’ve ever had the pleasure of using. It’s joy to embed, it’s fun to use, and here’s the kicker: It’s more like Lisp/Scheme than you think. I recently saw an absolutely crazy implementation of linked lists, far crazier than the standard Lua implementation. Basically, implementing cons, car, and cdr gets us the linked list for free. The table based implementation may be faster. Note that this idea comes right out of the MIT Scheme lectures, and I believe it’s also in SICP.

function cons(a,b)
    return function (p)
        if p == 1 then
            return a

Understanding Common LISP

LISP is the perfect programming language. It is so perfect, it is shit. Well, okay it is not shit, it’s awesome, but when you first try to learn it, it is completely shit. It is the most obscure, abstract, whacked out language ever thought up. But it’s perfect. It is so elegant, and so simple, that  you just can’t believe it works that way. What makes LISP difficult to learn is that you spend half your time unlearning deeply ingrained prejudices about how things can or should be done.

Getting over this initial hump is the hardest thing about learning LISP. Oh, and the documentation can sometimes really suck. If LISP had PHP style documentation, it would totally rule. It would rule everything.

HTML5 Canvas: Smooth, variable width lines with transparency.

When making a drawing app with HTML5 canvas, you might come up against the problem of making a smooth, variable width line. Eventually you might find that you can make several calls to ctx.quadraticCurveTo(x,y,xc,yc) and get some kind of effect. If you stroke every 2 or 3 points, then as long as the line width is very small, you won’t notice the jaggedness.

Unfortunately, if you try to do this with semi-transparent lines, the effect is truly horrible. To solve this problem, instead of drawing lines, I simply draw very thin shapes, and fill them with a color. This allows for 1) variable thickness and 2) nice transparency. Variable transparency is a problem I haven’t quite figured out yet. It may require composing the shape from individual pixels, which is simply too slow, especially in IE.

What I am writing is a drawing App that works with the Wacom Web Plugin, and therefore varies line thickness based on pressure. I would like to vary opacity too, but this seems problematic right now. A solution that may be possible is to fill the shape with a complex gradient, if it is possible to create semi-transparent stops.

Here is an image of what the program does so far:

test

 

HTML5 Canvas, Pixel Compositing, Transparency, and why all the trivia!

One thing I really hate about new technology are all the early adopters who incessantly post the same trivial examples. They cross link them too. So you can go from one page to the next, and see essentially the same example, just with the bits renamed or moved around.

At a certain point, I got it into my head that I wanted to make a quickie HTML5 App that works with my Intuous5 Wacom Pad. Wacom has a web plugin that let’s you get data about pen pressure and so on from the tablet. So I started to work on it, and found the said trivial examples and started mashing something up. Pretty soon it became apparent that if I wanted my lines to look good, I might have to anti-alias them, or so I am trying, I don’t know if it will work, because I just spent the better part of 2 hours looking for a solution to a simple problem.

If you look for examples of pixel level manipulation for HTML5 Canvas, you will find the same trivial examples over and over again, which basically say:

var id = context.createImageData(1,1);

var d = id.data;