Saturday, July 25, 2026
HomeLanguagesJavascriptp5.js strokeCap() Function

p5.js strokeCap() Function

The strokeCap() function in p5.js is used to set the style of line endings. The ends of line can be rounded, squared or extended based on their parameters SQUARE, PROJECT, and ROUND. The default value is ROUND.

Syntax:

strokeCap( cap )

Parameters: This function accepts single parameter cap which holds the style of end of line (ROUND, SQUARE or PROJECT).

Example: This example shows all the different kinds of line ending edges.




function setup() {
  
    // Create canvas of given size
    createCanvas(400, 400);
}
  
function draw() {
  
    // Set the background color
    background(50);
  
    // Set the weight of line stroke
    strokeWeight(15);
  
    // Set the color of line stroke
    stroke(20, 250, 100);
  
    // Set different edges style
    strokeCap(SQUARE);
    line(100, 200, 300, 200);
  
    strokeCap(ROUND);
    line(100, 100, 300, 100);
  
    strokeCap(PROJECT);
    line(100, 300, 300, 300);
}


Output:

Reference: https://p5js.org/reference/#/p5/strokeCap

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS