Friday, October 10, 2025
HomeLanguagesJavascriptp5.js circle() Function

p5.js circle() Function

The circle() function is used to draw the circle on the screen. A circle is the closed shape. A circle can be created by using the center and radius of the circle.

Syntax:

circle(x, y, d)

Parameters:

  • x: It is used to set the x-coordinate of the center of the circle.
  • y: It is used to set the y-coordinate of the center of the circle.
  • d: It is used to set the diameter of the circle.

Example 1:




function setup() { 
      
    // Create Canvas of given size 
    createCanvas(400, 300); 
  
} 
  
function draw() { 
      
    background(220);
      
    // Use color() function
    let c = color('green');
  
    // Use fill() function to fill color
    fill(c);
    
    // Draw a circle 
    circle(200, 100, 150); 
    
}


Output:

Example 2:




function setup() { 
      
    // Create Canvas of given size 
    createCanvas(400, 300); 
  
} 
  
function draw() { 
      
    background(220);
    
    // Draw a circle 
    circle(200, 150, 150); 
    
    noFill();
    
    // Draw a circle 
    circle(100, 150, 150); 
    
    // Draw a circle 
    circle(150, 75, 150);
    
}


Output:

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

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS