redraww
This is *excellent* information\! Thank you for providing the console error.
The error message:
`p5.js says: “colorMode” could not be called as a function. Verify whether “p5” has “colorMode” in it and check the spelling, letter-casing (JavaScript is case-sensitive) and its type. Inline Babel script:30 Uncaught TypeError: p5.colorMode is not a function at generateColorPalette (:50:6)`
And the second one:
`p5.js:59795 Uncaught TypeError: Cannot read properties of undefined (reading ‘split’)`
These two errors point directly to the problem:
1. **`p5.colorMode is not a function` in `generateColorPalette`:**
This is the core issue. Inside your `generateColorPalette` function, you are trying to call `p5.colorMode(…)`. However, the `p5` object you’re getting from `window.p5` *outside* the sketch’s `setup` and `draw` methods is not the same `p` (the p5 instance) that is passed to `setup` and `draw`.
The `p5.colorMode` function (and `p5.color`, `p5.background`, etc.) are *instance methods*. They belong to a specific p5 sketch instance (`p`), not the global `p5` object or class.
2. **`Cannot read properties of undefined (reading ‘split’)`:**
This secondary error often arises when p5.js tries to process a color, but the `color` function itself failed because `colorMode` wasn’t set up correctly (or the `p5` object it’s operating on is not a proper instance). When `p5.color` (or `p.color`) doesn’t return a valid color object, subsequent operations on that “undefined” result in this error.
—–
### The Solution: Pass the `p` (p5 instance) to `generateColorPalette`
To fix this, the `generateColorPalette` function needs access to the specific p5 instance (`p`) that is currently rendering. We’ll modify it to accept `p` as an argument.
Here’s the corrected HTML. I’ve reverted the `p.draw` function back to your more complex visuals, but with the fix for `generateColorPalette`.
—–
“`html
Dynamic Visuals Web App
“`
Leave a Reply