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

ColorMode ('oklch') doesn't seem to be working properly. #51

Closed spctrm404 closed 3 months ago

spctrm404 commented 3 months ago

I found your project while I was considering whether I should access the canvas directly because p5.js didn't support color space including oklch. To see if it supports wide gamut, I tried to compare the color of p3 color gamut with its fallback through the code below.

function setup() {
  createCanvas(400, 400);
  background(220);
  colorMode('rgb');
  let colourRgb = '#ff0c52';
  colorMode('oklch');
  let colourOklch = color(0.637, 0.28, 16.57, 1);
  fill(colourRgb);
  rect(0, 0, width / 2, height);
  fill(colourOklch);
  rect(width / 2, 0, width / 2, height);
}

However, the error phrase below appeared on the console.

TypeError: Cannot read properties of undefined (reading '_q5Color')
    at $.fill (q5.js:642:11)
    at setup (sketch.js:10:3)
    at Q5.$.<computed> [as setup] (q5.js:209:17)
    at _start (q5.js:226:11)
    at new Q5 (q5.js:236:3)
    at HTMLDocument.<anonymous> (q5.js:270:23)

I think the fill function cannot accepts color data created through colorMode('oklch') as a variable, do I have to use a different method when using colorMode('oklch') or is it a feature that hasn't been implemented yet, or is it a bug? By the way, #ff0c52 appeared pinkish red but little bit saturated as intended, and oklch color was rendered...... gray.

quinton-ashley commented 3 months ago

Ah wow thanks for reporting this, not sure how it got messed up. Seems like changes I made to support oklch got reverted or didn't merge somewhere along the line. Just fixed this!

quinton-ashley commented 3 months ago

fixed in v2.0.15