Are properties such as fill color, stroke weight, text size, etc. write only?

Hi, this is a question I’ve had on my mind for quite a while, and I apologize in advance if someone already asked it, but is there any way to just ask processing what the current stroke weight is? Or the current fill color, or the current text size, or the current stroke color, or the current rectangle mode, or the current text alignment, etc.? Or are these just write-only values, which can only be changed with a function and can only be obtained by knowing what they are at the beginning, and then manually changing them every time they change?

If it’s the latter, may I know what these values are by default at the start of any program? Especially textSize, all I can figure out is that it’s somewhere between 11 and 13 at the start of a program.

Thanks!

Pretty sure it’s read only you can use variables if you want to read them.

If it’s only the text size you’re interested in, I can tell you that it’s 12. Says it right here in the source:

If you rather want to keep track of those values (fill, stroke, …) at runtime, I don’t think there’s an easy way to do that. Not without accessing code you’re not supposed to touch and are prevented from doing so.
You could create your own methods like fillCustom that just call fill under the hood and set a variable in the process, although that’s not an ideal solution either.

If that’s what you want I could go into more detail, but for now I just hope this helped you. :slight_smile:

1 Like

Hello,

Some insight I have gleaned from topics and Processing source code:

// Attributes Read
// v1.0.0
// GLV 2021-10-22

//Defaults
println(g.strokeWeight);
println(g.textSize);
println(hex(g.fillColor));
println(g.stroke);
println(g.fill);

//Test
strokeWeight(1);
println(g.strokeWeight);

textSize(1);
println(g.textSize);

fill(0xFF00FF00);
println(hex(g.fillColor));

noStroke();
println(g.stroke);

noFill();
println(g.fill);

:)

5 Likes

So then why does the code

text("Hello",width/2,height/2);
textSize(12);
text("Hello",width/2,height/2+20);

Produce two different looking strings of text?

1 Like

Hello @Math_Machine,

Good eye!

It may be related to the mode you are using.

Static mode:

image

Active mode:

void setup() 
  {
  size(100, 100);
  println(g.textSize);
  text("Hello",width/2,height/2);
  textSize(12);
  text("Hello",width/2,height/2+20);
  }

image

There is a reference in the source code to:
g = createPrimaryGraphics();

The defaults g.* may only apply to active mode with a setup() and draw()

Others may be able to comment with more clarity on this.

References:

Links above may take a moment to find the line in Google Chrome.

:)

2 Likes

Hey, so, how do I get vertical text align? Like, if I say “textAlign(LEFT, TOP)”, then ask to “println(g.textAlign)”, it’ll print out “LEFT”. What would I ask that would cause it to print “TOP”?