Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
normalize() example added.
  • Loading branch information
deveshidwivedi authored Jan 16, 2024
commit 0df1999756289900016196a50d597c2fefd33f5a
51 changes: 51 additions & 0 deletions src/webgl/p5.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,57 @@ p5.Geometry = class Geometry {
* Modifies all vertices to be centered within the range -100 to 100.
* @method normalize
* @chainable
* @example
*
* <div>
* <code>
* let myObject;
*
* function setup() {
* createCanvas(150, 150, WEBGL);
* myObject = new object();
* }
* function draw() {
* background(220);
* rotateX(frameCount * 0.01);
* rotateY(frameCount * 0.01);
* myObject.display();
* }
*
* class object {
* constructor() {
* this.vertices = [
* createVector(-15, -15, 0),
* createVector(15, -15, 0),
* createVector(15, 15, 0),
* createVector(-15, 15, 0),
* ];
*
* this.normalize();
* }
*
* normalize() {
* for (let v of this.vertices) {
* v.normalize();
* }
* }
*
* display() {
* beginShape();
* for (let i = 0; i < this.vertices.length; i++) {
* vertex(this.vertices[i].x * 50, this.vertices[i].y * 50, this.vertices[i].z * 50);
* }
* endShape(CLOSE);
* }
* }
* </code>
* </div>
*
* @alt
* A continuously rotating square around the X and Y axes.
* </code>
* </div>
*
*/
normalize() {
if (this.vertices.length > 0) {
Expand Down