diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 7a16d04a23..0eab25a80f 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -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 p5.Image object. + * + * @example + *
+ * // 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
+ * });
+ *
+ * // 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);
+ *
+ * // Display the off-screen buffer on the main canvas
+ * image(myBuffer, -width / 2, -height / 2); // Draw the buffer on the main canvas
+ * }
+ *
+ *