q5js/q5.js

`image.get()` failing

Closed this issue · 4 comments

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?

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.

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
}

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