Skip to content

docs: add documentation for mix() method in p5.strands#8463

Merged
perminder-17 merged 2 commits into
processing:dev-2.0from
Anshumancanrock:mix
May 15, 2026
Merged

docs: add documentation for mix() method in p5.strands#8463
perminder-17 merged 2 commits into
processing:dev-2.0from
Anshumancanrock:mix

Conversation

@Anshumancanrock
Copy link
Copy Markdown

@Anshumancanrock Anshumancanrock commented Jan 28, 2026

Resolves #8441

Changes:

Added documentation for the mix() method in p5.strands. This GLSL built-in function was already implemented but missing from the reference documentation.

The documentation includes:

  • Method description and usage notes
  • Parameter and return type documentation
  • Three examples showing color blending, vertex manipulation, and gradient creation

PR Checklist

@welcome
Copy link
Copy Markdown

welcome Bot commented Jan 28, 2026

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

Comment thread src/strands/p5.strands.js Outdated
* let gradient = pixelInputs.uv.x;
* let color1 = vec3(1, 0.5, 0); // Orange
* let color2 = vec3(0.5, 0, 1); // Purple
* pixelInputs.color = vec4(mix(color1, color2, gradient), 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up, you may need to set pixelInputs.ambientColor = pixelInputs.color.rgb to avoid the default color still being used for ambient light.

Separately, we may want to open an issue to decide how to deal with that, since its somewhat unintuitive and a pretty common use case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up, you may need to set pixelInputs.ambientColor = pixelInputs.color.rgb to avoid the default color still being used for ambient light.

Separately, we may want to open an issue to decide how to deal with that, since its somewhat unintuitive and a pretty common use case.

Agreed, it does seem unintuitive that ambient color doesn't automatically follow the material color. Opening a separate issue would be a good idea. I will open one soon .

@davepagurek
Copy link
Copy Markdown
Contributor

I think this generally looks good, would you mind testing the examples in the p5.js-website repo (see instructions here https://github.com/processing/p5.js-website/blob/main/docs/scripts.md#testing-the-docs-of-your-fork) and showing screenshots of each? This also helps ensure they run correctly.

@Anshumancanrock Anshumancanrock force-pushed the mix branch 2 times, most recently from b1f7b3e to fb9dd40 Compare February 8, 2026 21:55
@Anshumancanrock
Copy link
Copy Markdown
Author

@davepagurek Thanks for the heads up! I've updated examples to use pixelInputs.ambientColor = pixelInputs.color.rgb. Should be cleaner this way.

@Anshumancanrock
Copy link
Copy Markdown
Author

@davepagurek I tested the examples locally on the p5.js-website by building the reference from my fork's branch. The mix() page renders correctly with all three examples. Here is the video:

ps51.mp4

The description, syntax, parameters, and all three examples (basic color mix, position-based mix, gradient mix) show up as expected.

Please let me know if you would like any further changes. Thank you :)

@perminder-17 perminder-17 self-requested a review May 15, 2026 06:20
Comment thread src/strands/p5.strands.js
* @param {Number|p5.Vector} x first value to interpolate from.
* @param {Number|p5.Vector} y second value to interpolate to.
* @param {Number|Boolean} a interpolation amount (0.0-1.0) or boolean selector.
* @return {Number|p5.Vector} interpolated value.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it locally, everything looks nice! I am merging this, but I have one concern on the return value.

mix() internally returns a StrandsNode, not a raw Number or [p5.Vector]. However, introducing a new StrandNode type in the docs might be confusing for beginners. I'm not sure whether using Number | p5.Vector is the right approach here, or if there's a better way to document this that stays accurate while still being user-friendly.

From my point of view, I am okay with keeping the return value as {Number|p5.Vector}.

CC: @davepagurek @ksen0 any thoughts on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we've been avoiding adding actual types here in curly braces and have just been describing the objects like "a three-dimensional vector" etc. We maybe would want to do a similar update here for consistency, but it might make sense later to make some types in the docs for p5.strands, but yeah, it's a little confusing too -- they'd maybe warrant having their own docs pages to describe what you can do with them.

If we do another pass on docs for the types here, we should possibly also check the .d.ts generator script. Currently I think they manually add all the glsl functions from an array of them, but now that we have them in the jsdoc too, we'll likely be double-exporting types for them. Might need to do a .filter(...) on the array of GLSL functions in the .d.ts generator so that we ignore ones we've manually documented?

@p5-bot
Copy link
Copy Markdown

p5-bot Bot commented May 15, 2026

Continuous Release

CDN link

Published Packages

Commit hash: c2596f1

Previous deployments

This is an automated message.

@perminder-17 perminder-17 merged commit 8a28795 into processing:dev-2.0 May 15, 2026
5 checks passed
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.

3 participants