Saturday, October 3, 2009

According to the Plan

… this shouldn't be happening.

In a previous post outlining my DPS909Processing.js (Pjs) project plan, I sketched out the implementation of pushStyle() and popStyle() over a period of over two months. As it turns out this may have been overly pessimistic.

Climbing the Stairs

In the beginning, the scheme called for storing and retrieving states from a nice 2D array. I opted for an object to store each state snapshot.I peeked into the Java Processing code (PStyle.java) to see what sort of variables I might be looking for. The variables listed under the comment // “Private" variables used to maintain state seemed like a good place to start.

Throwing the code into a test page, let's just say those were not, or not all, the variables I was looking for.

Finding the Elevator

Closer examination revealed a mysterious object stored as curContext, and it seemed the object's squishy innards contained what I was looking for. Since those innards didn't seem to be defined in the Pjs library I turned to Google, and that turned up the canvas element documentation.

As it turns out canvas comes fully equipped with functions to save and retrieve state snapshots. So using those functions instead of the array, and state-saving objects, we get something like:



Assuming one's browser comes with the requisite bells and whistles, it should look suspiciously similar to the Processing example.

Expanding the Catch

In terms of getting pushStyle() and popStyle() to work, there are a few things I still need to look into. In my current revision I am not handling any of the library's own variables at all. The basic example works without them but, but some may be relevant state variables and I have to figure out which ones (if any) are so.

Another concern is browser compatibility. Canvas implementation seems to be all across the board right now. If Pjs has to work now, without reservations, then I'll have to go back to the state-saving object and array scheme, while saving all of the canvas variables manually. On the other hand, if the onus is not on Pjs to work on browser's with incomplete canvas implementations, then that's one less thing to worry about.

But the bottom line is that the project as I envisioned it will most likely be done long before early December. This is not acceptable for DPS909 and therefore I must find additional bits of Pjs to hack away at. I'll be figuring that out soonish and changing altering my wiki project page to reflect that.

1 comment:

Unknown said...

Awesome work! Keep pushing, you're on the right path now.

Post a Comment