Closer to release 0.5
With a little luck, this should be my the last piece for the 0.5 release of Processing.js (Pjs) . The nf() function should now be able to handle arrays of numbers to be formatted, and float formatting.
There's a few interesting things going on here that the Processing documentation doesn't allude to, but those are more easily revealed once we see the code in action.
A few pixels
Here's the first batch of tests in Pjs (hah, there's no way I'm trying to minify that for the post!) and here's what Processing generates for the same code:
And here's the second batch of tests (arrays) in Pjs, and here's what Processing generates for the same code:
Note the tests use String::equals() which I recently completed and is not yet in the public release.
Also, while the documentation says all arguments should be positive integers, Processing's nf() does handle arguments with values zero or less. So I've coded Pjs' version to do the same.
It's supposed to do that? behaviour.
There are two weirder-than-normal things going on.
In the tests 19 to 32 in the first batch you'll find that depending on whether the one's digit is odd or even, the 'rounding' is different. This required a bit of extra code to replicate.
In the second batch, nf() processes values in the int array “incorrectly"; running through the ints individually results in the expected results. Strangely enough, my code was able to replicate this behaviour right off the bat.http://wobblyretroaction.blogspot.com/2010/01/processingjs-stringequals-or-how-i.html