Experiment: flatter strands API #8314
Open
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.
This partially addresses #7994 and #7992.
The core issue is that a single p5.strands shader involves two callback functions, which is kind of a lot. The outermost one is there because we need to isolate the code that we need to transpile, so that isn't immediately going away (a short term option could be to let people load that from a file rather than a function; a longer term option could be to transpile the whole file via a custom script tag type.) This PR doesn't address that outer one. In this I'm trying to chip away at the inner callback that currently is used for each hook.
Changes:
In general, instead of doing a callback for a hook, you can use begin/end. e.g.:
Live:
https://editor.p5js.org/davepagurek/sketches/oTsFO63lk
Both forms still work for backwards compatibility.
The rules currently are this:
.begin()/.end()block.resultproperty of the hookSome other potential thoughts that we could try out:
getPixelnputs.normal, should we make a globalinputsthat aliases the hook within itsbegin/endso you could writeinputs.normal?get*-prefixed hooks, likegetPixelInputs, topixelInputsso it reads more clearly in this form?getColorhook has two arguments,inputsandcanvasContent, the properties ofinputsaren't directly accessible, e.g. you'd have to dogetColor.inputs.texCoordrather than justgetColor.texCoord. So maybe we'd need to update the rules to give direct access to properties when there's only one object input? (I just don't want name clashes if someone makes a hook that takes two object arguments of the same type.)PR Checklist
npm run lintpasses