-
Hello! So I have this state Inside my sketch function I created a const sketch = (p5: P5CanvasInstance) => {
let hue = 0
p5.updateWithProps = (props:IProps) => {
if(props.hue) {
hue = props.hue
}
palette(p5, hue)
}
p5.setup = () => {
p5.createCanvas(WIDTH, HEIGHT)
p5.background(BG)
}
p5.windowResized = () => {
palette(p5, hue)
} and this works well, but I'm wondering how would the code look like if I want to use abstracted functions: const sketch = (p5: P5CanvasInstance) => {
let hue = 0
p5.updateWithProps = updateWithProps(p5)
p5.setup = setup(p5)
p5.windowResized = windowResized(p5) How would I set and get the hue variable in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
You would need to do it inside those functions before the returned function which takes the props inside there. Just like in the non-abstracted version. Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
sorry but I'm still confused.. In the minimal example above: const sketch = (p5: P5CanvasInstance) => {
let hue = 0
p5.updateWithProps = updateWithProps(p5)
p5.setup = setup(p5)
p5.windowResized = windowResized(p5)
} Would you be able to show an example? I'm trying but have no idea how to pass the const updateWithProps = (p5: P5CanvasInstance) => {
return (props: IProps) => {
tonalPalette(p5, 12, props.hue)
}
}
const windowResized = (p5: P5CanvasInstance) => {
return (props: IProps) => {
tonalPalette(p5, 12, props.hue)
}
} Right now when I resize the window the |
Beta Was this translation helpful? Give feedback.
I refactored your solution a little: