q5js / q5.js

A sequel to p5.js that's smaller, faster, and optimized for interactive art!
https://q5js.org
GNU Lesser General Public License v3.0
106 stars 8 forks source link

`image.get()` failing #72

Open tmjoen opened 6 days ago

tmjoen commented 6 days ago

Sorry for the noob question, but I can't seem to find any info on this.

I'm getting

Uncaught TypeError: $.Color is not a constructor
    at $.get (q5.js:1364:14)

This is in this code

  $.get = (x, y, w, h) => {
    let pd = $._pixelDensity || 1
    if (x !== undefined && w === undefined) {
      let c = $._getImageData(x * pd, y * pd, 1, 1).data
      return new $.Color(c[0], c[1], c[2], c[3] / 255)
    }

I can't find any $.Color defined — is this from an external lib?

quinton-ashley commented 5 days ago

Can you send me a snippet of your code that triggers the error?

Also Color is from the q5-color module which is included in the default q5.js bundle.

tmjoen commented 5 days ago

Thanks for taking a look, I really appreciate it!

The error appears when I load an image and try to manipulate it.

let img = loadImage('/images/and03-01.png')

// then later in draw()
function draw() {
  // ...
  let c = img.get(x * tileSizeX, y * tileSizeY) // this triggers the $.Color error
}
quinton-ashley commented 5 days ago

@tmjoen ah yup this is a bug. I will try to fix it soon.