Add p5.strands documentation and examples for color functions#8965
Add p5.strands documentation and examples for color functions#8965Yashisinghal285 wants to merge 8 commits into
Conversation
…lpha, hue, saturation, brightness, lightness
|
Thanks for the PR @Yashisinghal285! Good start - the strands descriptions for each function are accurate. A few things to fix before this is ready: 1. Examples are incomplete/incorrect
2.
|
…s.color pattern, complete sketches, describe()
|
Thanks @LalitNarayanYadav for the detailed feedback! Fixed all 5 points:
On the {myp5} scope note — checked test/unit/assets/testMaterial.js, which uses global-mode getPixelInputs() (no prefix), matching what I used and consistent with the rest of this file's examples. Let me know if you meant something different. |
|
Thanks for the updates @Yashisinghal285! Getting closer, but a few things still need fixing: 1. Examples still won't runThe strands examples are missing function setup() {
createCanvas(100, 100, WEBGL);
let myShader = baseMaterialShader().modify(() => {
getFinalColor((col) => {
let c = color('#ff0000');
col.rgb = c.rgb;
return col;
});
});
shader(myShader);
noStroke();
plane(100, 100);
describe('A red plane');
}2.
|
|
Thanks @LalitNarayanYadav — |
|
Thanks for addressing the feedback, @Yashisinghal285! The switch to @davepagurek @ksen0, this should be ready for maintainer review whenever you have a chance. |
davepagurek
left a comment
There was a problem hiding this comment.
Hi! If you take a look at the other examples on beta.p5js.org/reference, you'll notice they follow some different conventions.
- We don't use
baseMaterialShader().modify(...); instead, we madebuildMaterialShader(...)methods and use those in all the docs. The rationale is that the extra syntax provided more areas for users to get tripped up without giving much benefit, so we introduce people instead to the simpler single function (while still doing the more complex one under the hood internally.) - We try not to use inline anonymous functions in shader callbacks. This works, but it's again a question of minimizing the new things readers have to understand in order to read the example. Since users will already by familiar with named top-level functions in order to create the
function setupandfunction drawof p5, in examples, we prefer creating an additional top-level function likefunction myMaterialand then callingbuildMaterialShader(myMaterial). - Similar to the above, we have moved away from using the callback syntax to fill out the hooks in a shader. Nested functions provide an additional layer of syntactic complexity for users to understand, so rather than using
getFinalColor(() => { ... }), our p5.strands examples universally use afinalColor.begin(); ...; finalColor.end()syntax instead. Where a callback would return a value, we usefinalColor.set(...). Functions that just modify inputs (e.g.worldInputs) do not need to call.setat all.
For examples, we want to make sure that they actually run successfully and display the thing we want them to display. For that reason, rather than just writing it and trying to imagine what they do, we ask you to clone the p5.js-website repo, run it locally using your build of p5, and show us a screenshot of the results in a comment. See our contributor docs here for instructions on how to do that. This lets us also discuss whether anything could be visually improved, not just in the code.
Lastly, we also want to make sure that users aren't bogged down by all the possible ways one can use a function before seeing examples. For that reason, and because p5.strands is an advanced use case that most won't initially use, we should avoid adding text to the first big block of explanations above the simple examples, and instead put the explanation of p5.strands right before the relevant p5.strands example at the end of the reference page. To be able to have text in between examples, we will need to convert the examples for a reference entry from @examples to three-backtick-fenced examples. See the explanation here for details.
| * function setup() { | ||
| * createCanvas(100, 100, WEBGL); | ||
| * | ||
| * myShader = baseMaterialShader().modify(() => { |
There was a problem hiding this comment.
A p5.strands example should not be the first thing users see for red, let's put it at the end. We should maybe also move the explanation for how it works with p5.strands to the end too, right above it.
In order to do that, we need to switch from using these @example blocks to using three-backtick code fences. See this description in our contributor docs for what that looks like. This means we'll need to convert the existing examples for this reference into that format in order to be able to put text between the examples to add the explanation for p5.strands.
Closes #8915
Adds p5.strands-specific documentation and examples for color(), green(), blue(), alpha(), hue(), saturation(), brightness(), and lightness() in src/color/creating_reading.js. (red() and lerpColor() already had strand notes/examples from #8822.)
Each function's JSDoc now includes:
Examples were kept minimal and focused per the style guide, as discussed in the issue thread.
cc @LalitNarayanYadav for review