p5.js library for rendering of platonic solids.
solid([length = 100], [center = createVector()], [colors], [fuse = false])
Where solid
can be one of the following functions: tetrahedron
, hexahedron
(or cube
), octahedron
, dodecahedron
, or icosahedron
. The optional colors
array specifies colors for each vertex, and the fuse
parameter determines if colors are blended across faces. Parameters can be provided in any order.
To define a retained mode platonic solid use beginGeometry and endGeometry. For example, the following snippet defines a retained mode dodecahedronModel
:
let dodecahedronModel
function setup() {
beginGeometry()
dodecahedron(args) // See the previous section for arguments
dodecahedronModel = this.endGeometry()
dodecahedronModel.clearColors() // Optional
dodecahedronModel.computeNormals() // Optional
}
Render it with:
function draw() {
model(dodecahedronModel)
}
Link the p5.platonic.js
library into your HTML file, after you have linked in p5.js. For example:
<!doctype html>
<html>
<head>
<script src="p5.js"></script>
<script src="p5.sound.js"></script>
<script src=https://cdn.jsdelivr.net/gh/VisualComputing/p5.platonic/p5.platonic.js></script>
<script src="sketch.js"></script>
</head>
<body>
</body>
</html>
to include its minified version use:
<script src=https://cdn.jsdelivr.net/gh/VisualComputing/p5.platonic/p5.platonic.min.js></script>
instead.
Clone the repo (git clone https://github.com/VisualComputing/p5.platonic
) and open it with your favorite editor.
Don't forget to check these p5.js references: