Monday, April 11, 2011

0.7 and 0.8 - Dual release, now with moar web workers

For anyone who doesn't know Sundae, is a canvas reference tester library built in Javascript. My goal is get Processing.js, c3dl, and XB-pointstream to use this tool.


What's new?

Blurring is. Blurring is the basically smudging the image, the reason any tester needs this is because colours will render differently on different browsers. So if you took a reference screen shot and compare it to a real time render often times during an exact pixel comparison there will be slight variations. So in order to remove these useless errors I added two things. I stole all of my blurring logic from the Kraken javascript benchmarker here. Then I happily thrifted through the code that birthed Sundae, the Pjs ref tester and took their comparison logic.

So in short what's new is that a majority of the heavy lifting and work in the libraries engine is done. Now that compare and blurring are working I can take a sigh of relief.


The Unsung Hero's

Finally this project has web workers, why are they good? because it's the equivalent of putting something on the back burning and forgetting about it until you remember and its perfectly cooked the next time you look at it. Having the ability to throw the work into a background process is great. The best part is you don't lose control of your browser.

 Using web workers is pretty simple to boot, I setup a worker pool in my main thread and each worker roughly looks like this.


 var worker = new Worker("blah.js");
worker.onmessage = function (event) {
...
};
worker.postMessage("meaningful data"); 


Meanwhile in blah.js


onmessage = function (event) {
event.data //the data throw in during mains postmessage 
...
postMessage("throwing back response"); 
}



So main posts data to the worker, the worker gets it in it's onmessage and the original data is accessed by looking at event.data. When the worker is done is throws data back to main by calling postMessage, where the onmessage is main catches it.


Really Unsung Hero's

The other features I put in for these releases such as finally making the test tags working. Marking the end in an era where I had options on the front page of index.html that never did anything. Additionally getting to features that my one user so far wanted! Notes per test to display additional text during run time. Lastly, this option I spent a better part of Friday afternoon hacking together. Allowing the user to see the blurred pixel results on their original canvases as seen below.


Some Problems

I need help! Look at my thread pool in Sundae.js  I want each blurring to use its own worker thread. Right now the blur worker is blurring both canvases. I cannot not figure out how to get both of these threads running asynchronously and actually blurring the right canvases. If anyone has design advice drop a bug at lighthouse or comment below.

Friday, April 8, 2011

ECL500 - Drawsy

Dave Seifried and I created a simple paint application for the Blackberry. We made this application to be our culminating project in ECL500, the purpose of the course was to explore Eclipse as a development environment and ultimately use its tools to make something cool!

The Problems
 
An on going problem is combating the low frame rate environment. Since our draw function is called every frame often times a long sweeping motion leaves gaps because the motion took place between screen refreshes. Unfortunately this problem only gets worst the deeper our stack depth gets.

The Evolution
 
Originally we were going to port Processing to use RIM's awt implementation this proved to be quite the hassle, then we thought of using Processing.js, which was the reason I made this demo but the in ability to open local .html files and not wanting to rely on a network connection cut that dream short.

Either way here's your exclusive sneak peak at our demo.



Optimizations in the Works
  • Swipe the draw from the previous screen to the current
  • Draw on a back buffer
  • Better control of the screen stack

Sunday, March 27, 2011

pjs - fun - playing with a demo

The Demo

A few days ago, David Sefried linked me this demo.

The Hack

Because I don't own an IPad I ported over the demo to use with my mouse and my shiny new browser, Firefox 4!

I simply changed the touch event handling to mouse events, and where the multiple touch aspect became relevant I was forced to omit it. The code is available here on github. Just like the demo I used minified Processing.js, and both rewriting the code and fully understanding it was a breeze.

(function (w, undef) {
    var c, p, t, touches, go, 
    resize = function () {
        p.size(w.innerWidth, w.innerHeight);
    };
    w.touchStart = function (e) { touches = e; go = true; };
    w.touchMove = function (e) { if (go) touches = e; };
    w.touchEnd = function () { touches = go = undef; };
    w.orientationChange = resize;
    w.onload = function () {
        c = w.document.getElementById("art");
        p = new Processing(c, function (p) {
            p.setup = function () { p.background(255, 255, 230); }
            p.draw = function () {
                if (touches != undef) {
                    var r = (Math.sin(t) / 2.0 + 0.5) * 255;
                    var g = (Math.sin(t * 1.3) / 2.0 + 0.5) * 255;
                    var b = (Math.sin(t * 1.4) / 2.0 + 0.5) * 255;
                    p.noStroke();
                    p.fill(r, g, b);
                    t += 0.1;
                    p.ellipse(touches.pageX, touches.pageY, 300, 300);
                }
            }
        });
        t = 0;
        resize();
    };
})(window);



In Action

Click inside the canvas, and move your mouse around. The math that I do not understand takes care of the colour changing.


The Link

Here's the link to the hosted code, if you didn't read it off the URL.

Whats Next
 
I attempted to convert the code to generate a Mandelbrot fractals instead of just ellipses'. After no success so far I opted to upload working code. Thanks to Pomax in Pjs' irc channel for this link

Monday, March 7, 2011

ClassNamer

A change of pace from the usual javascript talk. A friend linked me this the other day, I thought it was genius at the time and its hilarity is now also heightened because of the fact that I didn't sleep last night thanks to work.

Behold:

http://www.classnamer.com/


Can't think of a class name sometimes? This is the link for YOU. it artfully selects arbitrary programming terms and commonly used words to make the most descriptive and utterly useless class names ever! I love it. This will surely benefit the community.