When I use the height
and width
as a constant I was wondering why it's giving me the value 100? Is it because size();
was not declared above? How do I set it to the size of the canvas? Because the following prints 100
Any help would do!!
Here is a copy of my code:
final int SIZE = height;
void setup() {
size (1000,1000);
println(SIZE);
}
See the processing documentation for size():
and
height
:This means as long
size()
was not called, the values forheight
andwidth
are initialized to 100.If you read the variables before, as you do it, then they will return 100.
You have to initialize
SIZE
after callingsize()
:The
width
andheight
variables are set when you call thesize()
function. You're using them outside of a function, which means they're happening before thesize()
function is called, which is why they still have their default values.To fix this, you need to move the variable initialization to be after
size()
is called:For primitive types the value itself is stored in a variable. So when you call
final int SIZE = height;
SIZE
will have the value whichheight
had immediately prior to that assignment. All subsequent changes toheight
will not affectSIZE
.