We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Both the reference page for size() and the new book on Processing by Reas and Fry state that the call to size() must be the first line in code, or the first line in setup(). I am not sure how strict this rule is, because it's actually violated even in the book in an example on p. 300.
My question is: is it safe to specify the parameters to size() as constants, for example as follows:
final int H=100;
size (2*H, H);
This technique has worked in my tests, but is it safe?
I know that it would be possible to first define the constants outside setup(), and then use them as parameters to size() in setup(), but as a programming teacher I would like to introduce the use of constants before I introduce setup() and draw() and defining functions in general.
I have two reasons for wanting to specify parameters to size() as constants.
First, assume that the width:height ratio of the sketch should always be 2:1, but the actual size might change. Then good programming practice states that size should be specified as above, not by size(200,100), where you would have to change two values if size of the sketch were changed.
Second, I would prefer that the students specify the width and height of the sketch with their own constants, and use those constants in calculations at other places in the code, rather than the students using the internal variables "width" and "height".
Answers
https://Processing.org/reference/settings_.html
GoToLoop,
I just installed 3.0 beta 3 and yes, using constants in size() no longer works.
I would like to make a petition: if at all possible, could the developers please enable the use of constants in call to size(). Note: constants, not variables.
GoToLoop,
thanks! I opened an issue in github, so at least they know about it now.
Much appreciated.
https://GitHub.com/processing/processing/issues/3632
PS3 has a new method settings () which you can use to set the size using variables and probably constants.
Sorry mised the 'immediate mode' part.