Specifically, this is the part I find confusing:
$('.red').change(function(){
pix = imageData.data;
for(var i = 0, n = pix.length; i < n; i += 4){
var green = 1, blue = 1;
pix[i] = pix[i] * $(this).val();
pix[i + 1] = pix[i + 1] * green;
pix[i + 2] = pix[i + 2] * blue;
}
context.putImageData(imageData, 0, 0);
});
How is it that modifying pix (which should be in the global scope) modifies the imageData object? Javascript does not directly support pointers.
No, but it is a reference, which has very similar semantics. You’re not creating a copy in that assignment. Objects are passed by reference, primitive types by value.