From c8ba7a6b1f6406af3036fcda4b86ca057d982951 Mon Sep 17 00:00:00 2001 From: "David.Rodrigues" Date: Thu, 8 Nov 2018 11:13:36 +0000 Subject: [PATCH] added early pget --- src/color.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/color.js b/src/color.js index c04b78c..82a980c 100644 --- a/src/color.js +++ b/src/color.js @@ -1,16 +1,16 @@ class Dave { // Short version of functions bellow. - constructor(){ - this.grid=new Grid(); + constructor() { + this.grid = new Grid(); this.g = this.grid; } // alias for fillHsluv f(h, s, l) { - this.fillHsluv(h,s,l); + this.fillHsluv(h, s, l); } // alias for strokeHsluv s(h, s, l) { - this.strokeHsluv(h,s,l); + this.strokeHsluv(h, s, l); } // sets fill according to hsluv parameters fillHsluv(h, s, l) { @@ -22,4 +22,23 @@ class Dave { let rgb = hsluv.hsluvToRgb([h, s, l]); stroke(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); } + // Create a fast get function to use instead of in P5. + pget(x, y, img) { + img.loadPixels(); + let d = pixelDensity(); + + for (var i = 0; i < d; i++) { + for (var j = 0; j < d; j++) { + // loop over + let idx = 4 * ((y * d + j) * img.width * d + (x * d + i)); + pixels[idx] = r; + pixels[idx + 1] = g; + pixels[idx + 2] = b; + pixels[idx + 3] = a; + } + } + // Things to take into consideration: x,y must be in image. + // pixelDensity has to be taken into consideration. + // loadPixels should be called only during the first time for this particular image. + } }