This project demoes:
The basic start can be used in a usecase, where you want to package your P5 creation in an npm package and publish it to NPM.
This work is based on webpack-sample.
The next usecase is to let a consumer provide the P5 skecth instance to a canvas-hosting webcomponent.
This work is based on create-react-app-sample. It is not fully done. PR's are welcome.
npm init stencil
# you get a menu - choose component
# Name of proejct: stncl-p5-poc
# Add dependencies:
npm install p5 --save
npm install @types/p5 --save-dev
# Test run: Build, start a webserver and a browser:
npm start
# Kill webserver:
ctrl-c
Add P5 to your webcomponent:
Edit webcomponent \stncl-p5-poc\src\components\my-component\my-component.tsx
// import p5
import p5 from 'p5';
// Paste demo code from
// https://github.com/p5-types/p5.ts/blob/master/examples/webpack/src/index.ts
function s(sketch: p5) {
const x = 100;
const y = 100;
sketch.setup = () => {
sketch.createCanvas(
200,
200
);
};
sketch.draw = () => {
sketch.background(
0
);
sketch.fill(
255
);
sketch.rect(
x,
y,
50,
50
);
};
};
const myp5 = new p5(
s
);
Now run the project once more.
Thats it!
Thanks to
The PoC was made at February code jam where also were present
- Event host: Carsten Høyer - Carsten Høyer (@cahodk) | Twitter - CarstenHoyer
- Hakim Mazouz - Mr. Mazouz (@devigner96) | Twitter - hakimmazouz - Hakim Mazouz on CodePen - Hakim Mazouz – Medium
- Niels Otto/
- Roar Engell - Roar Engell (@RoarEngell) | Twitter
- Danni Dromi - Danni Dromi (@PhallusInDaHaus) | Twitter - dromi
- Kristian Wichmann - Kristian Wichmann (@KristianWichman) | Twitter - kwichmann
- Carsten Jørgensen - Carsten Jørgensen (@Kahrzdn) | Twitter - Kahrzdn
- Mattia Paterna - Mattia Paterna (@inspiralpattern) | Twitter - inspiralpatterns
- Christian Lie
The End