As mentioned, how can processing.js respond to a browser\'s size? (responsive design) i\'ve tried screen.width and screen.height but it didn\'t work well. It seems only detect t
Here is how I approached this issue using Zerb Foundation 3 responsive web framework, Javascript, jQuery and Processing.js. You can take a look at Living Map Project if you want to dig through the source.
in javascript / jquery:
// handle page resizing
$(window).resize(function() {
var pjs = Processing.getInstanceById('livingmap');
pjs.resizeSketch(document.getElementById('div_p5canvas').offsetWidth, document.getElementById('div_p5canvas').offsetHeight);
} );
in your .pde processing js code (note: the calculation was what I felt worked well using zurb's foundation 3, the grid I defined and how that translated as pixels:
void resizeSketch(int w, int h) {
if (w < 680) {
size(w, floor(float(w)/680*610) - 30);
} else size(680, 610 - 30);
}
in your html: