I’ve been having trouble getting the p5.ColorGenerator library to work with newer versions of p5. Here is the code that actually does something:
There is more HTML than what is below, everything else is just boilerplate.
let colorGen;
function setup() {
createCanvas(600, 200);
background(100);
colorGen = new ColorGenerator("#ffba06");
colorGen.getShades(5).forEach((shade, index) => {
fill(shade);
rect(index * 100, 0, 100, 100);
});
}
This is what the repo recommends same exact code down to the version number in the CDN link. This does work, but I’d like to use a newer version of p5 (preferably the newest), and even though the repo says “It works with p5.js 1.4 and later”, it doesn’t work. I think something must have broke with the introduction of p5 v2? That is the only thing I can think of as of now. Does anyone know of a workaround that I can try? Or, if someone has a better library that they use to generate color pallets, that would be good too.
Another related issue I’m having is when I try to use this library as a module. Here is the code:
HTML without boilerplate:
JS:
import ColorGenerator from "https://cdn.jsdelivr.net/gh/alexandru-postolache/p5.colorGenerator@2.0.0/p5.colorGenerator.mjs";
All I’m doing is importing the module, and I get this error:
Uncaught SyntaxError: The requested module './p5.colorGenerator.js' does not provide an export named 'default'
Even weirder, I get the same exact error when I use the named import syntax:
import { ColorGenerator } ...
It still tells me that The requested module ‘./p5.colorGenerator.js’ does not provide an export named ‘default’, even though I’m using the named import syntax.
I also posted something similar on the repo as an issue.
Thanks!