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() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'green' );
sphere(100);
}
|
Output:
Example 2: This example uses sphere() function to draw the circle.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'yellow' );
rotateX(frameCount * 0.01);
rotate(frameCount*0.03);
sphere(140);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/sphere
Last Updated :
11 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...