Skip to content

Support colorMode() in p5.strands so color() can build colors from HSB/HSL values - #9443

Open
Akshats-git wants to merge 3 commits into
processing:mainfrom
Akshats-git:feat/strands-colormode-9432
Open

Akshats-git wants to merge 3 commits into
processing:mainfrom
Akshats-git:feat/strands-colormode-9432

Conversation

@Akshats-git

Copy link
Copy Markdown
Contributor

Resolves #9432

Changes:

As discussed with @davepagurek on Discord, colorMode() is now part of the strands state like noiseDetail().

  • colorMode() inside a shader only affects that shader. It no longer changes the sketch's color mode. If it isn't called then the sketch's color mode is used.
  • color() now works with shader values like color(hue(c), 1, 1). Before, these compiled to NaN. The result is always an RGBA vec4.
  • RGB, HSB and HSL are supported for now. Other modes show a friendly error with shader values but still work with plain numbers and strings.
  • saturation() returns HSB saturation in HSB mode, so it pairs with brightness(). A color like #ff8080 now round trips correctly.
  • The conversion uses fract() instead of mod() so WebGL and WebGPU give the same result.
  • Updated the reference notes that said colorMode() has no effect in strands and added a hue-shifting example to color().

One question: shader values use the colorMode ranges like plain numbers do. So to pass hue() and friends back into color() we need colorMode(HSB, 1) since they return 0-1. I can switch it so strands always reads shader values as 0-1 if you would prefer.

AI disclosure: I used Claude to help write parts of the code and tests. I reviewed and tested all of it.

PR Checklist

Calling colorMode() inside a shader now only affects that shader,
not the whole sketch. Part of processing#9432.
In HSB mode it now returns HSB saturation, so it pairs with
brightness(). Part of processing#9432.
Things like color(hue(c), 1, 1) now work in RGB, HSB and HSL
instead of compiling to NaN. Also updates the docs. Closes processing#9432.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support colorMode() in p5.strands so color() can build colors from HSB/HSL values

1 participant