Is there a way to change the thickness/width of line without using stroke weight?

Hello

i’m looking for a way to change the thickness of line(x1,y1,x2,y2) without using stroke weight, because stroke weight affects all shapes on canvas while i just want it to affect the line itself.

is there a way to do that? or at least “restrict” the stroke weight to affect only the drawn line?

please help me

thanks

You could use push() before and pop() after calling strokeWeight(...) to restore the original state.

See the documentation.

2 Likes

strokeWeight(7);
line… // thick
strokeWeight(1);
line… // thin
line…

This is what you want;

void setup() {
    size(900, 600);

    circle(width*0.25, height/2, 200);

    line(0, 0, width, height, 10);

    circle(width*0.50, height/2, 200);

    line(width, 0, 0, height, 15);

    circle(width*0.75, height/2, 200);
}

void line(float x1, float y1, float x2, float y2, float weight) {
    pushStyle();
    strokeWeight(weight);
    line(x1, y1, x2, y2);
    popStyle();
}

Hello,

See the p5.js references:

https://p5js.org/reference/#/p5/push

:)

2 Likes