2

I'm writing a processingjs script that I want to resize depending on the users viewport width. As far as I know there's no functionality for this in processing, so I've been looking at JQuery and using $(window).width();.

Only I don't know how to get that value into the size(width, height) function in processing.

Any ideas?

Thanks

Links if you need them: http://processingjs.org/ http://api.jquery.com/width/

Marcus Whybrow
  • 19,578
  • 9
  • 70
  • 90
logic-unit
  • 4,195
  • 12
  • 47
  • 72

1 Answers1

5

You can call $(window).width(); in the size function. Mixing js and p5 code is fine in processing.js.

void setup() {
    size( $(window).width(),
        $(window).height() );
    ...
}
Jacob
  • 77,566
  • 24
  • 149
  • 228
humphd
  • 76
  • 1
  • I don't suppose you know how to update the size if the browser resizes... I've created a function to set the size and can pass it parameters on window resize event. However the drawing never gets redrawn... – Matt Canty Sep 24 '14 at 09:17
  • setup() gets called once at the beginning of a processing program. draw() gets called continuously. – Andrew Mar 16 '15 at 04:30