How to get current stroke weight?

I can set strokeWeight(x) but I can’t find a method to return the current weight.

1 Like

you can store it every time you use strokeWeight(x)

you can even write a function for this like

before setup(): float currentStrokeWeight;

function:

void strokeWeightMy( float x) {
   strokeWeight(x) ;
   currentStrokeWeight=x; 
}
1 Like

There’s no method for it but a field within the PGraphics class named strokeWeight:
Processing.GitHub.io/processing-javadocs/core/processing/core/PGraphics.html#strokeWeight

Access the PGraphics main canvas via PApplet::g field or PApplet::getGraphics() method:
Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#g
Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#getGraphics--

println(g.strokeWeight); // 1.0
strokeWeight(2.5);
println(getGraphics().strokeWeight); // 2.5
exit();
5 Likes

Thanks! Follow on question: g.strokeColor is just a single int, how do I get r/g/b/a which is also an option to stroke() ?

  1. Processing.org/reference/red_.html
  2. Processing.org/reference/green_.html
  3. Processing.org/reference/blue_.html
  4. Processing.org/reference/alpha_.html
2 Likes