Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/math/noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,36 @@ function noise(p5, fn){
* }
* }
* }
*
* `noise()` can also be used in shaders with p5.strands, where it returns
* values in the range 0 to 1. The following example uses `noise()` to create
* a cloud-like texture effect in a filter shader.
*
* ```js example
* let myFilter;
*
* function setup() {
* createCanvas(100, 100, WEBGL);
* myFilter = buildFilterShader(shaderCallback);
* describe('A cloud-like noise pattern.');
* }
*
* function shaderCallback() {
* filterColor.begin();
* let coord = filterColor.texCoord;
* let t = millis() / 2000;
* // noise() returns values in the range 0 to 1.
* let mixFraction = noise(coord.x * 5, coord.y * 5, t);
* let darkBlue = [0.1, 0.1, 0.3, 1];
* let lightBlue = [0.9, 0.9, 1, 1];
* filterColor.set(mix(darkBlue, lightBlue, mixFraction));
* filterColor.end();
* }
*
* function draw() {
* filter(myFilter);
* }
* ```
*/
fn.noise = function(x, y = 0, z = 0) {
if (perlin == null) {
Expand Down
29 changes: 29 additions & 0 deletions src/math/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,35 @@ function random(p5, fn){
* // Draw the point.
* 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

* uses `random()` to create varying colors on a shape.
*
* ```js example
* let myShader;
*
* function setup() {
* createCanvas(100, 100, WEBGL);
* myShader = buildColorShader(shaderCallback);
* describe('A sphere with randomly varying colors.');
* }
*
* function shaderCallback() {
* let r = random();
* let g = random();
* let b = random();
* finalColor.begin();
* finalColor.set([r, g, b, 1]);
* finalColor.end();
* }
*
* function draw() {
* background(220);
* shader(myShader);
* noStroke();
* sphere(30);
* }
* ```
*/
/**
* @method random
Expand Down
30 changes: 30 additions & 0 deletions src/utilities/time_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ function timeDate(p5, fn){
* `The text "It took ${round(ms, 2)} ms to load the data" written in black on a gray background.`
* );
* }
*
* `millis()` can also be used in shaders with p5.strands. The following example
* uses `millis()` to create time-based color transitions on a shape.
*
* ```js example
* let myShader;
*
* function setup() {
* createCanvas(100, 100, WEBGL);
* myShader = buildColorShader(shaderCallback);
* describe('A sphere whose color shifts over time.');
* }
*
* function shaderCallback() {
* let t = millis() * 0.001;
* let value = 0.5 + 0.5 * sin(t);
* let skyBlue = [0.2, 0.6, 0.8, 1];
* let magenta = [0.8, 0.2, 0.6, 1];
* finalColor.begin();
* finalColor.set(mix(skyBlue, magenta, value));
* finalColor.end();
* }
*
* function draw() {
* background(220);
* shader(myShader);
* noStroke();
* sphere(30);
* }
* ```
*/
fn.millis = function() {
if (this._millisStart === -1) {
Expand Down
Loading