Hello,
I took an example from codingtrain and rewrote it to typescritpt. Unfortunately, it does not show any animation in the browser. Here is the code:
src/sketch.ts:
import 'p5';
import { Bubble } from "./Bubble";
let sketch = (p: p5) => {
let bubble1;
let bubble2;
p.setup = () => {
p.createCanvas(600, 400);
bubble1 = new Bubble(200, 200, 40);
bubble2 = new Bubble(400, 200, 20);
}
p.draw = () => {
p.background(0);
bubble1.move(p);
bubble1.show(p);
bubble2.move(p);
bubble2.show(p);
}
}
var sketchP = new p5(sketch);
src/Bubble.ts:
export class Bubble {
constructor(
public x: number,
public y: number,
public r: number) {
}
move(p: p5) {
this.x = this.x + p.random(-5, 5);
this.y = this.y + p.random(-5, 5);
}
show(p: p5) {
p.stroke(255);
p.strokeWeight(4);
p.noFill();
p.ellipse(this.x, this.y, this.r * 2);
}
}
fuse.js:
const {FuseBox, WebIndexPlugin} = require('fuse-box');
const fuse = FuseBox.init({
homeDir: 'src',
output: 'dist/$name.js',
sourceMaps: true,
globals: { "p5": "p5" },
plugins: [
WebIndexPlugin(),
]
});
fuse.dev({open : true});
fuse.bundle('app')
.instructions('> sketch.ts +p5')
.hmr({reload: true})
.watch()
fuse.run();
package.json:
{
"name": "p5-typescript-starter",
"version": "1.0.1",
"description": "Project to quickly get something working in [p5.js](https://p5js.org/) and [typescript](https://www.typescriptlang.org/)",
"scripts": {
"compile": "tsc",
"sketch": "node fuse.js"
},
"homepage": "https://github.com/mictadlo/p5-typescript-fuse-box-starter",
"repository": {
"type": "git",
"url": "git@github.com:mictadlo/p5-typescript-fuse-box-starter.git"
},
"dependencies": {
"p5": "^0.6.1"
},
"devDependencies": {
"@types/node": "^10.1.3",
"fuse-box": "^3.2.2",
"typescript": "^2.8.3",
"uglify-es": "^3.3.9",
"uglify-js": "^3.3.27"
}
}
What did I miss?
Thank you in advance.
Michal