Keep the strokeWeight() constant using scale

Hi people;

When I use scale, the function scales the strokeWeight(); too, how can avoid it?


void setup() {
  size(640,480);
  rectMode(CENTER);
}

void draw() {
  rect(50,50,50,50);
  scale(2,2);
  rect(50,50,50,50);  
}
1 Like

I think you should just scale the strokeWeight with a reciprocate value. Here’s an example altering the code you sent:

float scale=1;
void setup() {
  size(640,480);
  rectMode(CENTER);
}

void draw() {
    scale+=.1;
  strokeWeight(1/scale);
  scale(scale,scale);
  rect(50,50,50,50);  
}
4 Likes

Hello,

This is one way:
https://processing.org/reference/noStroke_.html

May not be the solution you are looking for though.

That is my chuckle for the day.

You could also “scale” with a factor in your code the parameters in rect():
https://processing.org/reference/rect_.html
I have done this on occasion depending on project.

:)

1 Like

Mmmm seems it’s the camera(); + zoom what is making my lines horrible…

Using scale and increasing the scale (zoom) works well, until the camera() changes.

My question was wrong formulated, thank you guys.

@Spaceman1 probably that’s the solution for my proffer question

@glv yes, is a solution because the strokeWeight(); wont variate xP , but I need the stroke to represent the line xD Tried your second suggestion too, multiplying the factors of each X , Y value, but seems that the scale affects things that I don’t know and in my whole project all the representation mess up.

One last question; what is affected by Scale? And what is the value that multiplies the strokeWeight(); if I use scale(x,y);?

1 Like

There isn’t one value, and it isn’t multiplied by the weight. That isn’t what scale is doing. Scale is a 2d transformation on the total output – it isn’t changing the strokeWeight setting at all.

To see this in action, try passing separate x and y values to scale().

/**
 * Scale and strokeWeight
 * 2020-07-27 Jeremy Douglass - Processing 3.5.4
 *
 * press space to see how 2d scale may affect
 * stroke weight at different orientations
 * https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/4
 */
void setup() {
  size(400,400);
  strokeWeight(20);
}
void draw() {
  background(255);
  if(keyPressed) scale(1.8, 1.0);
  line(0,0,width/4.0,height/4.0);
  line(width/4.0, height/4.0, width/2.0, height/4.0);
  line(width/2.0, height/4.0, width/2.0, height/2.0);
  line(width/2.0, height/2.0, width, height);
}

ScaleAndStrokeWeight--screenshot-1


ScaleAndStrokeWeight--screenshot-2

As you can see, the horizontal line weight is not scaled (y * 1.0), the vertical line is much thicker (x * 1.8), and the diagonal line is in-between – it is horizontally 1.8x thicker, but that makes its effective weight the hypotenuse of a 1.0 x 1.8 right triangle. If it were at a different angle, it would have a different weight.

2 Likes