p5.js torus() Function
Last Updated :
11 Aug, 2023
The torus() function in p5.js is used to draw a torus with given torus radius and tube radius.
Syntax:
torus( radius, tubeRadius, detailX, detailY )
Parameters: This function accepts four parameters as mentioned above and described below:
radius: This parameter stores the radius of the torus.
tubeRadius: This parameter stores the radius of the tube.
detailX: This parameter stores the number of segments in x-dimension.
detailY: This parameter stores the number of segments in y-dimension.
Below programs illustrate the torus() function in p5.js:
Example 1: This example uses torus() function to draw a torus with given torus radius and tube radius.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'green' );
torus(90, 35, 12, 12);
}
|
Output:
Example 2: This example uses torus() function to draw a torus with given torus radius and tube radius.
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
fill( 'yellow' );
rotateX(frameCount * 0.01);
rotate(frameCount*0.05);
torus(90, 35);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/torus
Share your thoughts in the comments
Please Login to comment...