feat(strands): add color() support for beginner-friendly color inputs#8822
Open
LalitNarayanYadav wants to merge 4 commits into
Open
feat(strands): add color() support for beginner-friendly color inputs#8822LalitNarayanYadav wants to merge 4 commits into
LalitNarayanYadav wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the Open Source Software Microgrant: beginner-friendly p5.strands API for more p5-like color support.
Changes
Adds beginner-friendly p5.js-style color support inside the strands context, so users can work with familiar color APIs in shaders instead of raw
vec4literals.color()- parse any p5.js color input into avec4Previously, calling
color()inside amodify()block returned ap5.Colorobject, unusable in a GPU shader context. This PR overridescolor()instrands_api.jsto return avec4strands node instead.Supported input formats (all handled by p5's existing
colorjs.ioparser):color('#ff0000'),color('#f00')color('red'),color('cornflowerblue')rgb()/rgba()strings:color('rgb(255, 0, 0)')color(255, 0, 0),color(128)(grayscale)How it works:
p5.color()to parse the input, no new parsing logic._getRGBA()on the result to get[r, g, b, a]normalized to 0–1vec4strands node viaprimitiveConstructorNodelerpColor(c1, c2, amt)- interpolate between two colorsMaps directly to GLSL
mix()in the strands context, since colors arevec4s. Falls through to normal p5 behavior outside strands.red(),green(),blue(),alpha()- component accessorsExtract scalar RGBA channels from a
vec4color node via.x/.y/.z/.wswizzles.hue(),saturation(),brightness(),lightness()- HSL/HSB accessorsInject GLSL helper functions (
_p5_rgb2hsb,_p5_rgb2hsl) into the shader declarations on first use, then extract the relevant channel from the convertedvec3. Helpers are injected into vertex, fragment, and compute declarations.Outside a strands context, all functions fall through to normal p5 behavior.
Example
Screenshots
N/A - shader/transpiler change with no visual diff.
PR Checklist
npm run lintpasses