From bb4dde087ddc06342d3e4d50a0ca96d82b64a482 Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Sun, 11 Aug 2024 08:47:01 +0100 Subject: [PATCH 1/5] Added Example on p5.Framebuffer.get method --- src/webgl/p5.Framebuffer.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 7a16d04a23..089782115d 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -1479,6 +1479,37 @@ 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(400, 400, WEBGL); + * + * // Create an off-screen WebGL graphics buffer + * let myBuffer = createGraphics(200, 200, WEBGL); + * + * // Draw a red box on the off-screen buffer + * myBuffer.background(0); // Set the background to black + * myBuffer.noStroke(); + * myBuffer.fill(255, 0, 0); // Set the fill color to red + * myBuffer.push(); + * myBuffer.translate(0, 0, 0); + * myBuffer.box(100); // Draw a red box at the center + * myBuffer.pop(); + * + * // 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 + * } + * + *
*/ /** * @method get From aea7d413d0fb3f406c4bd6b0ca219c8771b9b56f Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Thu, 22 Aug 2024 09:34:26 +0100 Subject: [PATCH 2/5] removed Graphics on Framebuffer get method --- src/webgl/p5.Framebuffer.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 089782115d..eea0bd1f05 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -1489,16 +1489,17 @@ class Framebuffer { * createCanvas(400, 400, WEBGL); * * // Create an off-screen WebGL graphics buffer - * let myBuffer = createGraphics(200, 200, WEBGL); - * + * let myBuffer = createFramebuffer({ width: 200, height: 200 }); * // Draw a red box on the off-screen buffer - * myBuffer.background(0); // Set the background to black - * myBuffer.noStroke(); - * myBuffer.fill(255, 0, 0); // Set the fill color to red - * myBuffer.push(); - * myBuffer.translate(0, 0, 0); - * myBuffer.box(100); // Draw a red box at the center - * myBuffer.pop(); + * myBuffer.draw(() => { + * background(0); // Set the background to black + * noStroke(); + * fill(255, 0, 0); // Set the fill color to red + * push(); + * translate(0, 0, 0); + * box(100); // Draw a red box at the center + * pop(); + * }) * * // Get the color of a pixel at the center of the box (in 2D coordinates) * myBuffer.loadPixels(); // Load the pixel data for myBuffer From 170894dedcdd993219e492fe0f9310dd0cebc085 Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Thu, 22 Aug 2024 09:37:51 +0100 Subject: [PATCH 3/5] lint fix --- src/webgl/p5.Framebuffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index eea0bd1f05..6a540b8ef1 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -1499,7 +1499,7 @@ class Framebuffer { * translate(0, 0, 0); * box(100); // Draw a red box at the center * pop(); - * }) + * }); * * // Get the color of a pixel at the center of the box (in 2D coordinates) * myBuffer.loadPixels(); // Load the pixel data for myBuffer From d46a582306ea5d23d536ea4cb53c571cfd205f9b Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Mon, 26 Aug 2024 02:01:50 +0100 Subject: [PATCH 4/5] removed pop push and translate --- src/webgl/p5.Framebuffer.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 6a540b8ef1..26d423f93e 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -1495,10 +1495,7 @@ class Framebuffer { * background(0); // Set the background to black * noStroke(); * fill(255, 0, 0); // Set the fill color to red - * push(); - * translate(0, 0, 0); * box(100); // Draw a red box at the center - * pop(); * }); * * // Get the color of a pixel at the center of the box (in 2D coordinates) From 7b1cba7f37018d70c692cc18f9bfdf10f6971b7f Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Mon, 26 Aug 2024 23:26:13 +0100 Subject: [PATCH 5/5] changed canvas size --- src/webgl/p5.Framebuffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 26d423f93e..0eab25a80f 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -1486,7 +1486,7 @@ class Framebuffer { * // The `pixelColor` is logged to the console, returning red with full opacity. * * function setup() { - * createCanvas(400, 400, WEBGL); + * createCanvas(100, 100, WEBGL); * * // Create an off-screen WebGL graphics buffer * let myBuffer = createFramebuffer({ width: 200, height: 200 });