Monday, October 12, 2009

boolean() for Processing.js

And so we return for another (short) post in the irregular series on “What is Matthew doing with Processing.js?" Ah, the joys of lagging a bit behind from where where I should be. But onwards to putting a little bit more on my plate!

Seeking truth From variables

There is a spectre haunting the incompleteness of Processing.js (Pjs) (well, one of many spectres) - the spectre of boolean(). It is a spectre I hope to, at least, partially exorcise by December.

This little function takes a variable, may it be integer, String, object, or an array thereof, and spits out “true" of “false" (or even an array of such). A little peeking into the original Java code shows that the function is actually spread over five overloaded Java methods in class PApplet.

Of course, it will all have to be condensed into a single function in Pjs. Since it doesn't seem JavaScript requires the explicit declaration of data types, I'll have to search around to see how one might go about distinguishing between them. However I expect there will be plenty of examples to sink my teeth into. (I can't be the first person to ask: “How do I tell if a variable is an array?" after all!)

The project page has been given a minor revision to reflect the new bit on the plate. I really must get around to jotting down some documentation on my latest work with pushStyle() and popStyle(). See? Lagging behind.

Speaking of which...

In my previous post I displayed a basic working example for pushStyle() and popStyle(). Alas, I hosted the JavaScript library on a temperamental web host so it can't be seen half the time.

I redisplay the example here using (hopefully) a more reliable web host.



But where has the time gone? Release version 0.1 is just around the corner, and there is still things to ponder and code to crunch! I guess it would not be a student's life if one did not feel kinship to the tardy White Rabbit.

1 comment:

Unknown said...

How to tell if a value is an array (via Crockford p. 106):


function isArray(some_value) {
if (some_value && typeof some_value === 'object' && some_value.constructor === Array)
return true;
return false;
}

Post a Comment