MCPcopy
hub / github.com/processing/p5.js / get

Method get

src/core/p5.Renderer.js:295–326  ·  view source on GitHub ↗
(x, y, w, h)

Source from the content-addressed store, hash-verified

293 }
294
295 get(x, y, w, h) {
296 const pd = this._pixelDensity;
297 const canvas = this.canvas;
298
299 if (typeof x === 'undefined' && typeof y === 'undefined') {
300 // get()
301 x = y = 0;
302 w = this.width;
303 h = this.height;
304 } else {
305 x *= pd;
306 y *= pd;
307
308 if (typeof w === 'undefined' && typeof h === 'undefined') {
309 // get(x,y)
310 if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) {
311 return [0, 0, 0, 0];
312 }
313
314 return this._getPixel(x, y);
315 }
316 // get(x,y,w,h)
317 }
318
319 const region = new Image(w*pd, h*pd);
320 region.pixelDensity(pd);
321 region.canvas
322 .getContext('2d')
323 .drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w*pd, h*pd);
324
325 return region;
326 }
327
328 scale(x, y){
329

Callers 2

validateFunction · 0.45
toStringMethod · 0.45

Calls 2

pixelDensityMethod · 0.95
_getPixelMethod · 0.45

Tested by

no test coverage detected