Get Viewport Width With JQuery and Use In Processing JS
Asked Answered
S

1

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/

Sweated answered 8/1, 2011 at 1:59 Comment(0)
V
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() );
    ...
}
Vashtivashtia answered 8/1, 2011 at 2:9 Comment(2)
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...Cunningham
setup() gets called once at the beginning of a processing program. draw() gets called continuously.Azotemia

© 2022 - 2024 — McMap. All rights reserved.