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
fix linting errors
  • Loading branch information
deveshidwivedi authored Jan 19, 2024
commit 8f91ad7b031c7a7db64c4d65a3f870b2d9e5ce0c
87 changes: 42 additions & 45 deletions src/webgl/p5.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,30 @@ p5.Geometry = class Geometry {
* <code>
*
* let customGeometry;
* class CustomGeometry {
* constructor(size) {
* this.vertices = [
* createVector(0, -size / 2, 0),
* createVector(size / 2, size / 2, size / 2),
* createVector(-size / 2, size / 2, size / 2),
* createVector(-size / 2, size / 2, -size / 2),
* createVector(size / 2, size / 2, -size / 2)
* ];
* this.faces = [];
* this.computeFaces();
* }
*
* computeFaces() {
* this.faces = [
* [0, 1, 2], // Bottom face
* [0, 2, 3], // Left face
* [0, 3, 4], // Front face
* [0, 4, 1], // Right face
* [1, 4, 3], // Back face
* [1, 3, 2] // Base face
* ];
* }
* }
* function setup() {
* createCanvas(150, 150, WEBGL);
* customGeometry = new CustomGeometry(50);
Expand All @@ -314,41 +337,15 @@ p5.Geometry = class Geometry {
* for (let vertexIndex of face) {
* let vertexPosition = customGeometry.vertices[vertexIndex];
* vertex(vertexPosition.x, vertexPosition.y, vertexPosition.z);
* }
* }
* endShape();
* }
*
* class CustomGeometry {
* constructor(size) {
* this.vertices = [
* createVector(0, -size / 2, 0),
* createVector(size / 2, size / 2, size / 2),
* createVector(-size / 2, size / 2, size / 2),
* createVector(-size / 2, size / 2, -size / 2),
* createVector(size / 2, size / 2, -size / 2)
* ];
* this.faces = [];
* this.computeFaces();
* }
*
* computeFaces() {
* this.faces = [
* [0, 1, 2], // Bottom face
* [0, 2, 3], // Left face
* [0, 3, 4], // Front face
* [0, 4, 1], // Right face
* [1, 4, 3], // Back face
* [1, 3, 2] // Base face
* ];
* }
* }
* endShape();
* }
*
* </code>
* </div>
* @alt
* A dynamically rotating 3D pyramid, crafted with triangular faces through custom geometry computations.
*
*/
computeFaces() {
this.faces.length = 0;
Expand Down Expand Up @@ -900,27 +897,16 @@ p5.Geometry = class Geometry {
* <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),
* createVector(-15, 15, 0)
* ];
*
* this.normalize();
* this.normalize();
* }
*
* normalize() {
Expand All @@ -931,20 +917,31 @@ p5.Geometry = class Geometry {
*
* 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);
* }
* 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);
* }
* }
*
* function setup() {
* createCanvas(150, 150, WEBGL);
* myObject = new object();
* }
* function draw() {
* background(220);
* rotateX(frameCount * 0.01);
* rotateY(frameCount * 0.01);
* myObject.display();
* }
* </code>
* </div>
*
* @alt
* A continuously rotating square around the X and Y axes.
* </code>
* </div>
*
*/
normalize() {
if (this.vertices.length > 0) {
Expand Down