The stroke() function is used to draw the lines and border around the text and shapes. The color object can be set in terms of RGB or HSB depending on the color mode. The color object can also be set as string in terms of RGB, RGBA, Hex CSS color or named color string. Syntax:
stroke( v1, v2, v3, alpha )
or
stroke( value )
or
stroke( gray, alpha )
or
stroke( values )
or
stroke( color )
Parameters:
- v1: It is used to set the red or hue value relative to current color range.
- v2: It is used to set the green or saturation value relative to current color range.
- v3: It is used to set the blue or brightness value relative to current color range.
- alpha: It is used to set the transparency of the drawing.
- value: It is used to set the value of color string.
- gray: It is used to set the gray value.
- values: It is an array containing the red, green, blue and alpha value.
- color: It is used to set the stroke color.
Below examples illustrate the stroke() function in p5.js: Example 1:
javascript
function setup() {
createCanvas(400, 200);
}
function draw() {
background(220);
strokeWeight(10);
stroke( 'green' );
fill( 'white' );
circle(90, 90, 34);
textSize(20);
text( "GeeksForGeeks" , 140, 100);
}
|
Output:
Example 2:
javascript
function setup() {
createCanvas(400, 200);
}
function draw() {
background(220);
stroke( 'orange' );
strokeWeight(30);
line(100, 50, 300, 50);
stroke( 'white' );
strokeWeight(30);
line(100, 100, 300, 100);
stroke( 'green' );
strokeWeight(30);
line(100, 150, 300, 150);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/stroke
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
11 Aug, 2023
Like Article
Save Article