Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | sphere() function

  • Last Updated : 22 Apr, 2019

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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!