FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   scale applet to browser window
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: scale applet to browser window  (Read 239 times)
mudpub

mudpubnet WWW
scale applet to browser window
« on: Jun 25th, 2004, 7:15pm »

hi.
 
i was wondering if anybody knew of a way to scale the processing applet to the window size of the web browser, while maintaining the width x height aspect ratio.
 
one thing i did think about was to get javascript to determine height and width of the browser window and use <PARAM> tag to pass on that information...but if anybody can think of a better way, that would be great.
 
-tak
 

mudpub.com / mudcorp.com / yale university school of art
toxi_
Guest
Email
Re: scale applet to browser window
« Reply #1 on: Jun 25th, 2004, 7:29pm »

you're almost there with you idea... just put this in your sketch:
Code:
void setup() {
  int ww, hh;
  // if online get size from <applet> tag
  if (online()) {
    ww = Integer.parseInt(param("width"));
    hh = Integer.parseInt(param("height"));
  } else {
    // ...or use this hardcoded setting
    ww = 640;
    hh = 480;
  }
  size(ww, hh);
}

 
...and in the html just do this:
 
Code:
<applet code="MyApplet" archive="MyApplet.jar" width="100%" height="100%"></applet>

 
hth!
 
justo


Re: scale applet to browser window
« Reply #2 on: Jun 25th, 2004, 8:49pm »

i'm not quite sure, but couldn't you also just ask the applet what size it was, then pass it on to the processing size() method?
 
like:
Code:
void setup() {  
  int ww = bounds().width;
  int hh = bounds().height;
 
  size(ww, hh);  
}

 
i dont have processing on this computer, so i can't test it out, but the applet's width and height is independent of the int array you are writing to...it should always return the current size of the whole applet.
 
mudpub

mudpubnet WWW
Re: scale applet to browser window
« Reply #3 on: Jun 27th, 2004, 5:44pm »

sweet! thanks toxi, that seems to work!
 
cool.
 
-tak.
 

mudpub.com / mudcorp.com / yale university school of art
Pages: 1 

« Previous topic | Next topic »