p5.js strokeWeight() function
Last Updated :
11 Aug, 2023
The strokeWeight() function in p5.js is used to set the width of the stroke used for lines, points and the border around shapes. The stroke weight is set by using pixels.
Syntax:
strokeWeight(weight)
Parameters: This function accepts a single parameter weight which stores the weight (in pixels) of the stroke. The below programs illustrate the strokeWeight() function in p5.js:
Example 1: This example uses strokeWeight() function to set the width of the stroke.
javascript
function setup() {
createCanvas(380, 170);
}
function draw() {
background(220);
strokeWeight(20);
fill( 'green' );
circle(60, 60, 34);
textSize(20);
text( "GeeksForGeeks" , 120, 70);
}
|
Output:
Example 2: This example uses strokeWeight() function to set the width of the stroke.
javascript
function setup() {
createCanvas(380, 170);
}
function draw() {
background(220);
stroke( 'orange' );
strokeWeight(10);
line(20, 70, 80, 70);
stroke( 'white' );
strokeWeight(8);
line(20, 90, 80, 90);
stroke( 'green' );
strokeWeight(6);
line(20, 110, 80, 110);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/strokeWeight
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...