Blogging about Hacker School?

Day 13

On Friday, we had some more of the “optional job-getting content” and I wrote some recursive functions in Python alongside Rebecca.

Today, I wrote a further piece of my exciting dishwashing sim game: the part in which you scrub the dishes. Instead of holding the background (clean plate) pixels in a buffer and examining them by hand, I went with a solution involving three stacked canvases. The bottommost canvas holds an image of the clean plate, and is only drawn to once, on load. The uppermost canvas draws the sponge cursor (tied to the mousemove event). The middle canvas holds the dirty dish image, and the magic is that the canvas composition modes include one in which the overlayed image is subtracted from the destination image, so all I have to do is draw a sponge-out image to the dirt layer while in “destination-out” compositing mode:

middlectx.globalCompositeOperation = "destination-out";
middlectx.drawImage(eraser, mouseX-eraser.width/2, mouseY-eraser.width/2);

So satisfying.

Code’s on Github.

Additionally, I had some theoretically-regularly-scheduled Sass time with Moshe. In the evening I enjoyed the talk by Yaron Minsky at Jane Street on concurrent programming, which was surprisingly accessible if necessarily constrained by the time.