Skip to content

Add shader examples to noise random and millis functions#8803

Merged
perminder-17 merged 4 commits into
processing:dev-2.0from
SOUMITRO-SAHA:docs-8777-strands-noise-random-time
May 20, 2026
Merged

Add shader examples to noise random and millis functions#8803
perminder-17 merged 4 commits into
processing:dev-2.0from
SOUMITRO-SAHA:docs-8777-strands-noise-random-time

Conversation

@SOUMITRO-SAHA
Copy link
Copy Markdown

Resolves #8777 (Noise, Random, Time batch)

Changes:
Adds inline p5.strands examples to the reference documentation for 3 functions across 3 files:

src/math/noise.js

  • noise() — cloud-like texture effect using buildFilterShader() with filterColor

src/math/random.js

  • random() — random RGB colors on a shape

src/utilities/time_date.js

  • millis() — time-based color transitions

Each example includes a brief explanation that the function can be used in shaders with p5.strands. The noise() example demonstrates buildFilterShader() for 2D filter effects, while random() and millis() use buildColorShader().

Screenshots of the change:

PR Checklist

Add practical examples showing how noise random and millis can be used
with p5.strands shader system including complete working code examples
for cloud effects random colors and time-based transitions
Copy link
Copy Markdown
Contributor

@nbogie nbogie left a comment

Choose a reason for hiding this comment

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

great!

Comment thread src/math/noise.js Outdated
* let coord = filterColor.texCoord;
* let t = millis() / 2000;
* let value = noise(coord.x * 5, coord.y * 5, t);
* filterColor.set(mix([0.1, 0.1, 0.3, 1], [0.9, 0.9, 1, 1], value));
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.

I think this could better be split out fully:

let mixFraction = noise( /* ... omitted... */)
let color1 = [0.1, 0.1, 0.3, 1]; 
let color2 = //etc
let mixedColor = mix(color1, color2, mixFraction)
filterColor.set(mixedColor)

Reasoning:

  • this might be read by someone coming to strands for the first time, who loves noise() and is excited to move on with it. The more we can do to reduce the chance of overwhelming them, the better.
  • shorter lines are also more readable on lower-res devices without wrap
  • separate lines allow easier experimentation and replacement in the editable sketch with less chance of the user getting in a mess

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.

I wonder if a second example showing the effects of noiseDetail would be suitable here, too (perhaps driven by the mouseX)? I guess that's for the noiseDetail() page itself but I worry about lesser discoverability of that.

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.

Sure! I'll add a second inline example on the noise() page showing noiseDetail() driven by mouseX. That way readers see both functions together without having to hunt for noiseDetail(). Pushing shortly!

Comment thread src/math/noise.js Outdated
* filterColor.begin();
* let coord = filterColor.texCoord;
* let t = millis() / 2000;
* let value = noise(coord.x * 5, coord.y * 5, t);
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.

I think it's worth commenting on what range of values noise will return here.

@p5-bot
Copy link
Copy Markdown

p5-bot Bot commented May 18, 2026

Copy link
Copy Markdown
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks @nbogie for the review, and @SOUMITRO-SAHA for the work on it.

@perminder-17 perminder-17 merged commit 00c91c4 into processing:dev-2.0 May 20, 2026
5 checks passed
Comment thread src/math/random.js
* point(x, y);
* }
*
* `random()` can also be used in shaders with p5.strands. The following example
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.

I think this has the same issue as before where the examples won't render because we have description + js example code fences below an @example tag -- we may need to do a follow-up PR fixing this one up

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.

aah, yes. Idk, how I missed this one. Will be opening up a follow-up PR now and will merge this one. Thanks for the finding.

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.

No problem, pretty hard to catch these except by testing on the website repo, which is pretty time consuming. Thanks for checking that on some of the other PRs, which alerted me to this being a potential problem!

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.

Here's the PR for the fix: #8816

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.

Thanks @perminder-17 for jumping on this fix! I'm sorry you had to do the extra work here. I wasn't previously aware of how to test the documentation rendering locally via the p5.js website, so I appreciate you explaining the setup. I've now pushed format fixes (@example → ``js example` fences) for #8801 and #8802

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.

4 participants