Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptp5.js sphere() function

p5.js sphere() function

The sphere() function in p5.js is used to draw a sphere with given radius.

Syntax:

sphere( radius )

Parameters: This function accepts single parameter radius which stores the radius of the sphere.

Below programs illustrate the sphere() function in p5.js:

Example 1: This example uses sphere() function to draw the circle.




function setup() {
      
    // Create Canvas of size 600*600
    createCanvas(600, 600, WEBGL);
}
   
function draw() {
      
    // Set background color
    background(200);
     
    // Set filled color of sphere
    fill('green');
     
    // sphere() function called
    sphere(100);
}


Output:

Example 2: This example uses sphere() function to draw the circle.




function setup() {
      
    // Create Canvas of size 600*600
    createCanvas(600, 600, WEBGL);
}
   
function draw() {
      
    // Set background color
    background(200);
     
    // Set filled color of sphere
    fill('yellow');
     
    // Rotate 
    rotateX(frameCount * 0.01);
    rotate(frameCount*0.03);
     
    // sphere() function called
    sphere(140);
}


Output:

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

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

Most Popular

Recent Comments