We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › difference for width/height in setup() and draw()
Page Index Toggle Pages: 1
difference for width/height in setup() and draw() (Read 210 times)
difference for width/height in setup() and draw()
Nov 20th, 2008, 1:34pm
 
Hi,

I stumbled upon a strange behavior regarding the canvas size.

If you run a processing sketch as applet in the browser you are able to change it's size via the width and height attributes of the <object> tag.

Nonetheless you need to call size() as first method in setup().

Now I have the situation where I export the applet with 640x480 but want to use it some times in 800x600.

Processing seems to override the values from size() with those provided by the HTML-tags! Is this documented somewhere? I looked at the documentation of size() and didn't find anything about applets and their size attributes?

In my case processing changes the size of the applet to match the HTML-attributes, but only AFTER setup() has finished.

As I'm doing some size specific initializations in setup() the difference between setup() and draw() causes my sketch to fail...

An example sketch which demonstrates this (simply export as applet and change the size in the HTML to 800x600):
void setup() {
 size(640, 480);
 println("setup size="+width+"x"+height);
 
 noLoop();
}

void draw() {
 println("draw size="+width+"x"+height);
}


Is this a bug? a feature? Did I do something wrong?
This size difference could explain why some sketches don't work on openprocessing.org when resized...


Thx Ilu
Re: difference for width/height in setup() and dra
Reply #1 - Nov 24th, 2008, 11:13am
 
some more experiments yield a "size initialization is nondeterministic"-behavior, at least for the size of the applet :(

these are the results from multiple hits on the reload-button with some more output:
void setup() {
 Dimension dim= getSize();
 println("dim size="+dim.getWidth()+"x"+dim.getHeight());
 println("isActive="+isActive());
 size(640, 480);
 println("setup size="+width+"x"+height);

 dim= getSize();
 println("dim size="+dim.getWidth()+"x"+dim.getHeight());

 noLoop();
}

void draw() {
 background(255, 0, 0);

 fill(0,255,0);
 rect(20, 20, width-40, height-40);

 println("draw size="+width+"x"+height);
}


dim size=800.0x480.0
setup size=640x480
dim size=640.0x480.0
draw size=640x480

dim size=800.0x480.0
setup size=640x480
dim size=800.0x480.0
draw size=640x480

dim size=800.0x480.0
setup size=640x480
dim size=800.0x480.0
draw size=640x480

dim size=800.0x480.0
setup size=640x480
dim size=800.0x480.0
draw size=640x480

dim size=800.0x480.0
setup size=640x480
dim size=640.0x480.0
draw size=640x480

So how can I run my sketch from processing with a useable size but can also change the size at deploy-time with the applets html-attributes?

I would expect size() to ignore the values when in applet mode.

Ilu
Page Index Toggle Pages: 1