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

Added Example on p5.Framebuffer.get method #7166

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
29 changes: 29 additions & 0 deletions src/webgl/p5.Framebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,35 @@ class Framebuffer {
* @param {Number} w width of the subsection to be returned.
* @param {Number} h height of the subsection to be returned.
* @return {p5.Image} subsection as a <a href="#/p5.Image">p5.Image</a> object.
*
* @example
* <div>
* <code>
* // The `pixelColor` is logged to the console, returning red with full opacity.
*
* function setup() {
* createCanvas(100, 100, WEBGL);
*
* // Create an off-screen WebGL graphics buffer
* let myBuffer = createFramebuffer({ width: 200, height: 200 });
* // Draw a red box on the off-screen buffer
* myBuffer.draw(() => {
* background(0); // Set the background to black
* noStroke();
* fill(255, 0, 0); // Set the fill color to red
* box(100); // Draw a red box at the center
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the size of the box to be 50 i.e. box(50) instead of 100

* });
*
* // Get the color of a pixel at the center of the box (in 2D coordinates)
* myBuffer.loadPixels(); // Load the pixel data for myBuffer
* let pixelColor = myBuffer.get(100, 100); // Get the color at (100, 100)
* console.log('Pixel color at (100, 100):', pixelColor);
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 run grunt yui:dev. For looking at the pixel color user needs to open dev tools.
Can we use text() for displaying the pixelColor on the canvas or maybe we could add a line to the description saying (this is what we get in console (in your words) maybe).

*
* // Display the off-screen buffer on the main canvas
* image(myBuffer, -width / 2, -height / 2); // Draw the buffer on the main canvas
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use -width and -height instead of dividing them with 2.

* }
* </code>
* </div>
*/
/**
* @method get
Expand Down
Loading