# Keep the strokeWeight() constant using scale

**URL:** <https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611>\
**Category:** Coding Questions\
**Created:** [July 14, 2020, 2:10pm UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611 "2020-07-14T14:10:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [July 14, 2020, 2:10pm UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/1 "2020-07-14T14:10:19Z")

</div>

Hi people;

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

```auto

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

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

```

---

<div class="post-metadata">

**Author:** ![Spaceman1](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/spaceman1/32/9970_2.png) [@Spaceman1](https://discourse.processing.org/u/Spaceman1)\
**Post date:** [July 14, 2020, 6:15pm UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/2 "2020-07-14T18:15:27Z")

</div>

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

```auto
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);  
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 15, 2020, 8:05am UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/3 "2020-07-15T08:05:57Z")

</div>

Hello,

This is one way:  
[https://processing.org/reference/noStroke\_.html](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](https://processing.org/reference/rect_.html)  
I have done this on occasion depending on project.

`:)`

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [July 15, 2020, 10:37am UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/4 "2020-07-15T10:37:21Z")

</div>

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](https://processing.org/reference/scale_.html)? And what is the value that multiplies the `strokeWeight();` if I use `scale(x,y);`?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [July 27, 2020, 8:48pm UTC](https://discourse.processing.org/t/keep-the-strokeweight-constant-using-scale/22611/5 "2020-07-27T20:48:21Z")

</div>

> [@Waboqueox](#):
>
> what is the value that multiplies the `strokeWeight();` if I use `scale(x,y);` ?

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()`.

```auto
/**
 * 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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9c42eb9ee051b330bd4848153a300a7fd7a3f656.png)

* * *

![ScaleAndStrokeWeight--screenshot-2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f411d58f8649447617873f1ffe00f69de1127df7.png)

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.
