Skip to content

VisualComputing/p5.platonic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

p5.platonic

p5.js library for rendering of platonic solids.

Platonic solids.

Usage

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.

Retained Mode

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)
}

Installation

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.

vs-code & vs-codium & gitpod hacking instructions

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:

  1. Library creation.
  2. Software architecture.
  3. Webgl mode.