Reference cylinder()

cylinder()

Draws a cylinder.

A cylinder is a 3D shape with triangular faces that connect a flat bottom to a flat top. Cylinders with few faces look like boxes. Cylinders with many faces have smooth surfaces.

The first parameter, radius, is optional. If a Number is passed, as in cylinder(20), it sets the radius of the cylinder’s base. By default, radius is 50.

The second parameter, height, is also optional. If a Number is passed, as in cylinder(20, 30), it sets the cylinder’s height. By default, height is set to the cylinder’s radius.

The third parameter, detailX, is also optional. If a Number is passed, as in cylinder(20, 30, 5), it sets the number of edges used to form the cylinder's top and bottom. Using more edges makes the top and bottom look more like circles. By default, detailX is 24.

The fourth parameter, detailY, is also optional. If a Number is passed, as in cylinder(20, 30, 5, 2), it sets the number of triangle subdivisions to use along the y-axis, between cylinder's the top and bottom. All 3D shapes are made by connecting triangles to form their surfaces. By default, detailY is 1.

The fifth parameter, bottomCap, is also optional. If a false is passed, as in cylinder(20, 30, 5, 2, false) the cylinder’s bottom won’t be drawn. By default, bottomCap is true.

The sixth parameter, topCap, is also optional. If a false is passed, as in cylinder(20, 30, 5, 2, false, false) the cylinder’s top won’t be drawn. By default, topCap is true.

Note: cylinder() can only be used in WebGL mode.

Examples

Syntax

cylinder([radius], [height], [detailX], [detailY], [bottomCap], [topCap])

Parameters

radius

radius of the cylinder. Defaults to 50.

height

height of the cylinder. Defaults to the value of radius.

detailX

number of edges along the top and bottom. Defaults to 24.

detailY

number of triangle subdivisions along the y-axis. Defaults to 1.

bottomCap

whether to draw the cylinder's bottom. Defaults to true.

topCap

whether to draw the cylinder's top. Defaults to true.

Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/3d_primitives.js and open a pull request!

Related References