Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made a new method to return Geometry with no internal colors. #6498

Merged
merged 11 commits into from
Oct 26, 2023

Conversation

perminder-17
Copy link
Contributor

@perminder-17 perminder-17 commented Oct 26, 2023

Resolves #6384

Changes:

PR.mp4

Description:

let shap01;
function setup() {
renderer = createCanvas(600, 600, WEBGL);
buildShape02();
}
function draw() {
background(0);
fill("yellow");
model(shape02);
}

function buildShape02() {
beginGeometry();
fill("red"); //The box is red
box(50);
shape02 = endGeometry();
shape02.clearColors(); //After calling this the box becomes yellow as it removes internal colors.
}

PR Checklist

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! I think we just want to add some documentation to the new method now.

* Clears the internal Color of the Geometry.
* @method clearColors
*/
p5.prototype.clearColors = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we can take out this method now that we have one on p5.Geometry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@@ -88,6 +88,10 @@ p5.Geometry = class Geometry {
this.dirtyFlags = {};
}

clearColors() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you can add a doc comment around this one? It would be nice to add your example in the video in your PR description. Maybe we can add two examples: one showing the behaviour without clearColors(), and one showing the behaviour with clearColors()?

Here's an example of a doc comment with an example sketch on another class. Adding one here would look similar:

/**
* Removes the framebuffer and frees its resources.
*
* @method remove
*
* @example
* <div>
* <code>
* let framebuffer;
* function setup() {
* createCanvas(100, 100, WEBGL);
* }
*
* function draw() {
* const useFramebuffer = (frameCount % 120) > 60;
* if (useFramebuffer && !framebuffer) {
* // Create a new framebuffer for us to use
* framebuffer = createFramebuffer();
* } else if (!useFramebuffer && framebuffer) {
* // Free the old framebuffer's resources
* framebuffer.remove();
* framebuffer = undefined;
* }
*
* background(255);
* if (useFramebuffer) {
* // Draw to the framebuffer
* framebuffer.begin();
* background(255);
* rotateX(frameCount * 0.01);
* rotateY(frameCount * 0.01);
* fill(255, 0, 0);
* box(30);
* framebuffer.end();
*
* image(framebuffer, -width/2, -height/2);
* }
* }
* </code>
* </div>
*
* @alt
* A rotating red cube blinks on and off every second.
*/
remove() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will add a doc comment around this one.

@perminder-17
Copy link
Contributor Author

@davepagurek , I have added a doc comment with two examples. Can you check and suggest what else we need?

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far, and great comments in the example! I just have a few more comments to clean up the example a bit.

* 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about putting the clearColors() here? It also works having it in draw, but it only needs to be called once, so it feels like only doing it once when building the shape fits more cleanly.

* let points = [];
*
* function setup() {
* renderer = createCanvas(600, 600, WEBGL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can take out the renderer = because we don't use it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yess... I will take out that.

@@ -87,7 +87,59 @@ p5.Geometry = class Geometry {

this.dirtyFlags = {};
}

/**
* Removes the internal Colors of p5.Geometry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add one more sentence after this explaining that this lets you supply new colors with fill() before drawing it? And otherwise, fill() gets ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I was also thinking of that... Okay going to add this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other small request: could we add a period at the end of the sentence so it fits with the style of the next bit of text? other than that I think everything looks good!

@@ -90,7 +90,7 @@ p5.Geometry = class Geometry {
/**
* Removes the internal Colors of p5.Geometry
* Using clearColors, you can use 'fill()' to supply new colors before drawing each shape.
* If clearColors() is not used, the shapes will use their internal colors.
* If clearColors() is not used, the shapes will use their internal colors by ignoring 'fill()'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use backticks around the function names, they'll get rendered like code:

by ignoring `fill()`.

...becomes:

by ignoring fill().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...gonna do it.

@perminder-17
Copy link
Contributor Author

@davepagurek Does it looks good now?

@perminder-17
Copy link
Contributor Author

Any other change you want @davepagurek ?

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two tiny things, and after that we're good to merge!

/**
* Removes the internal Colors of p5.Geometry.
* Using clearColors, you can use `fill()` to supply new colors before drawing each shape.
* If clearColors() is not used, the shapes will use their internal colors by ignoring `fill()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more spot where we can use backticks:

Suggested change
* If clearColors() is not used, the shapes will use their internal colors by ignoring `fill()`.
* If `clearColors()` is not used, the shapes will use their internal colors by ignoring `fill()`.

@@ -87,7 +87,60 @@ p5.Geometry = class Geometry {

this.dirtyFlags = {};
}

/**
* Removes the internal Colors of p5.Geometry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh also, we have an extra capital in here:

Suggested change
* Removes the internal Colors of p5.Geometry.
* Removes the internal colors of p5.Geometry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok gonna do ASAP, wait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw nice observation 😅

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to go now, thanks! 😁

@perminder-17
Copy link
Contributor Author

Sorry @davepagurek for these all mistakes. And thankyou so much for the constant support.

@davepagurek
Copy link
Contributor

No worries! Don't think of it so much as finding mistakes, rather it's just always helpful having an editor/reviewer to catch things that slip by. Hopefully it relieves some of the pressure knowing you don't have to get everything right yourself the first time because someone else is also helping to check!

@davepagurek davepagurek merged commit 611941a into processing:main Oct 26, 2023
2 checks passed
@perminder-17
Copy link
Contributor Author

No worries! Don't think of it so much as finding mistakes, rather it's just always helpful having an editor/reviewer to catch things that slip by. Hopefully it relieves some of the pressure knowing you don't have to get everything right yourself the first time because someone else is also helping to check!

Yes, Thankyou so much. Love to contribute more like this.

@perminder-17 perminder-17 deleted the clearColor branch October 26, 2023 23:21
@perminder-17 perminder-17 mentioned this pull request Jan 18, 2024
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vertex colors don't save in buildGeometry() with a single color, but do when multiple colors used
2 participants