Skip to main content

JavaScript

Hello rectangle!

hello-rectangle.js
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.js
├── index.html
└── p8g.js

0 directories, 3 files

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