Skip to main content

TypeScript

Hello rectangle!

hello-rectangle.ts
import p8g, {
background,
createCanvas,
rect,
} from './p8g.js';

p8g.draw = () => {
background(220);
rect(50, 50, 100, 100);
};

createCanvas(320, 320);
ScreenshotScreenshot
index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello rectangle!</title>
</head>
<body>
<script type="module" src="hello-rectangle.js"></script>
</body>
</html>

Run in browser

.
├── hello-rectangle.ts
├── index.html
├── p8g.d.ts
└── p8g.js

0 directories, 4 files

tsc hello-rectangle.ts --module esnext --target es2017

Use something like python -m http.server or https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer to serve your sketch during development.