File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,41 @@ import P5Wrapper from 'react-p5-wrapper';
4040<P5Wrapper sketch={sketch} />
4141```
4242
43- ### Properties
43+ An Sketch could look like this:
4444
45- * sketch: This is the Sketch Script which should be executed in the P5 Canvas (see Example)
45+ ```
46+ export default function sketch (p) {
47+ let rotation = 0;
48+
49+ p.setup = function () {
50+ p.createCanvas(600, 400, p.WEBGL);
51+ };
52+
53+ p.myCustomRedrawAccordingToNewPropsHandler = function (props) {
54+ if (props.rotation){
55+ rotation = props.rotation * Math.PI / 180;
56+ }
57+ };
58+
59+ p.draw = function () {
60+ p.background(100);
61+ p.noStroke();
62+ p.push();
63+ p.rotateY(rotation);
64+ p.box(100);
65+ p.pop();
66+ };
67+ };
68+ ```
4669
47- ### Notes
70+ In the Example above you see the ` myCustomRedrawAccordingToNewPropsHandler ` function.
71+ This function is called if Properties of the wrapper component are changing.
72+ In this case the Wrapper Component would be integrated like this: ` <P5Wrapper sketch={sketch} rotation={rotation}/> ` .
73+
74+ ### Properties
4875
49- You can add custom Properties, which can be used in the Sketch (see Example)
76+ * sketch: This is the Sketch Script which should be executed in the P5 Canvas
77+ * You can add as many custom Properties as you want
5078
5179
5280## Development (` src ` , ` lib ` and the build process)
Original file line number Diff line number Diff line change 11{
22 "name" : " react-p5-wrapper" ,
3- "version" : " 0.0.1 " ,
3+ "version" : " 0.0.2 " ,
44 "description" : " p5-wrapper" ,
55 "main" : " lib/P5Wrapper.js" ,
66 "author" : {
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ import p5 from 'p5';
44export default class P5Wrapper extends React . Component {
55
66 componentDidMount ( ) {
7- this . canvas = new p5 ( this . props . sketch , this . refs . wrapper )
7+ this . canvas = new p5 ( this . props . sketch , this . refs . wrapper ) ;
8+ this . canvas . myCustomRedrawAccordingToNewPropsHandler ( this . props ) ;
89 }
910
1011 componentWillReceiveProps ( newprops ) {
You can’t perform that action at this time.
0 commit comments