Skip to content

Commit

Permalink
Update p5.Geometry.js
Browse files Browse the repository at this point in the history
  • Loading branch information
perminder-17 authored Oct 26, 2023
1 parent e33224a commit df35dc0
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/webgl/p5.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,56 @@ p5.Geometry = class Geometry {

this.dirtyFlags = {};
}

/**
* Removes the internal Colors of p5.Geometry
*
* @method clearColors
*
* @example
* <div>
* <code>
* let shape01;
* let shape02;
* let points = [];
*
* function setup() {
* renderer = createCanvas(600, 600, WEBGL);
* points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0));
* buildShape01();
* buildShape02();
* }
* function draw() {
* background(0);
*
* fill("pink"); // shape01 retains its internal blue color, so it won't turn pink.
* model(shape01);
*
* shape02.clearColors(); // Resets shape02's colors.
* fill("yellow"); // Now, shape02 is yellow.
* model(shape02);
* }
*
* function buildShape01() {
* beginGeometry();
* fill("blue"); // shape01's color is blue because its internal colors remain.
* beginShape();
* for (let vec of points) vertex(vec.x * 100, vec.y * 100, vec.z * 100);
* endShape(CLOSE);
* shape01 = endGeometry();
* }
*
* function buildShape02() {
* beginGeometry();
* fill("red"); // shape02.clearColors() removes its internal colors. Now, shape02 is red.
* beginShape();
* for (let vec of points) vertex(vec.x * 200, vec.y * 200, vec.z * 200);
* endShape(CLOSE);
* shape02 = endGeometry();
* // You can also call shape02.clearColors() here.
* }
* </code>
* </div>
*/
clearColors() {
this.vertexColors = [];
return this;
Expand Down

0 comments on commit df35dc0

Please sign in to comment.