Most appropriate sub-area of p5.js?
p5.js version
2.3.2
Web browser and version
All
Operating system
All
Steps to reproduce this
If you are using instance mode, you have to pass in a second parameter to p5.strands containing whatever outside context you need in the shader. This gets passed back into the function you pass in, so you add an argument to your function to collect the data from the outside world. However, this currently throws an error, I assume because a regex doesn't handle param => { ... } correctly.
new p5(p => {
let gradientShader
p.setup = function() {
p.createCanvas(400, 400, p.WEBGL)
gradientShader = p.buildMaterialShader((param) => {
let { p } = param
let pos = p.sharedVec4()
p.worldInputs.begin();
pos = [p.worldInputs.position/200, 1];
p.worldInputs.end();
p.pixelInputs.begin();
p.pixelInputs.color = pos;
p.pixelInputs.end();
}, { p })
}
p.draw = function() {
p.clear()
p.shader(gradientShader)
p.noStroke()
p.plane(p.width, p.height)
}
})
Live: https://editor.p5js.org/davepagurek/sketches/k64e4h1LA
Notably, this works if you:
- Use
function(param) { ... }
- Use an arrow function with no args (e.g. in global mode)
- Destructure parameters directly in the parentheses instead of in the function body, e.g.
({ p }) => { ... } in the example above.
I believe we have tests that do some of the above, but I guess not this particular case.
Most appropriate sub-area of p5.js?
p5.js version
2.3.2
Web browser and version
All
Operating system
All
Steps to reproduce this
If you are using instance mode, you have to pass in a second parameter to p5.strands containing whatever outside context you need in the shader. This gets passed back into the function you pass in, so you add an argument to your function to collect the data from the outside world. However, this currently throws an error, I assume because a regex doesn't handle
param => { ... }correctly.Live: https://editor.p5js.org/davepagurek/sketches/k64e4h1LA
Notably, this works if you:
function(param) { ... }({ p }) => { ... }in the example above.I believe we have tests that do some of the above, but I guess not this particular case.