index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sketch</title>
<link rel="stylesheet" type="text/css" href="dist/style.css">
<!-- p5.min.js cdn -->
</head>
<body>
<script src="dist/sketch.js"></script>
</body>
</html>
sketch.ts
import * as p5 from "p5/index";
let sketch = (p: p5) => {
p.setup = () => {
p.createCanvas(p.width, p.height);
p.background(p.color(25));
}
p.draw = () => {
p.fill(p.color(200, 45, 6));
p.ellipse(p.random(0, p.width), p.random(0, p.height), p.random(0, 255));
}
};
sketch.js
var sketch = function (p) {
p.setup = function () {
p.createCanvas(p.width, p.height);
p.background(p.color(25));
};
p.draw = function () {
p.fill(p.color(200, 45, 6));
p.ellipse(p.random(0, p.width), p.random(0, p.height), p.random(0, 255));
};
};
I wrote this sketch based on some of the typescript related questions I’ve read but I’m having trouble with actually calling it on the page since the function sketch is looking for a p5 instance, how do I call it on my html page?