--- /dev/null
+module.exports = {
+ "env": {
+ "browser": true,
+ "es2021": true
+ },
+ "extends": "eslint:recommended",
+ "parserOptions": {
+ "ecmaVersion": "latest",
+ "sourceType": "module"
+ },
+ "rules": {
+ "indent": [
+ "error",
+ "tab"
+ ],
+ "linebreak-style": [
+ "error",
+ "unix"
+ ],
+ "quotes": [
+ "error",
+ "double"
+ ],
+ "semi": [
+ "error",
+ "always"
+ ],
+ "block-spacing": [
+ "error",
+ "never"
+ ],
+ "array-bracket-newline": [
+ "error",
+ "never"
+ ],
+ "array-element-newline": [
+ "error",
+ "never"
+ ],
+ "space-in-parens": [
+ "error",
+ "never"
+ ],
+ "array-bracket-spacing": [
+ "error",
+ "never"
+ ],
+ "object-curly-spacing": [
+ "error",
+ "never"
+ ],
+ "newline-per-chained-call": [
+ "error",
+ {"ignoreChainWithDepth": 1}
+ ],
+ "no-multi-spaces": [
+ "error"
+ ],
+ "dot-location": [
+ "error",
+ "object"
+ ]
+ }
+};
--- /dev/null
+{
+ "name": "pid",
+ "version": "1.0.0",
+ "description": "",
+ "source": "src/index.html",
+ "scripts": {
+ "start": "parcel serve --no-cache",
+ "build": "parcel build",
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "keywords": [],
+ "author": "Robin Krens",
+ "license": "ISC",
+ "dependencies": {
+ "planck": "^1.0.0"
+ },
+ "devDependencies": {
+ "eslint": "^8.56.0",
+ "parcel": "^2.11.0"
+ }
+}
--- /dev/null
+import {Vec2, Box, World} from "planck";
+
+// Get the canvas element
+const canvas = document.getElementById("area");
+const ctx = canvas.getContext("2d");
+
+// Create a <link>Planck.js</link> world
+const world = World(Vec2(0, 0));
+
+// Define the box properties
+const boxWidth = 50;
+const boxHeight = 50;
+
+// Create a dynamic body for the box
+const box = world.createDynamicBody(Vec2(200, 100));
+box.createFixture({
+ shape: Box(boxWidth / 2, boxHeight / 2),
+ density: 1.0,
+});
+
+// Render the box on the canvas
+function render() {
+ const position = box.getPosition();
+ const angle = box.getAngle();
+
+ // Clear the canvas
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Draw the box
+ ctx.save();
+ ctx.translate(position.x, position.y);
+ ctx.rotate(angle);
+ ctx.fillStyle = "#0095DD";
+ ctx.fillRect(-boxWidth / 2, -boxHeight / 2, boxWidth, boxHeight);
+ ctx.restore();
+}
+
+// Animation loop
+function animate() {
+ world.step(1 / 60);
+ render();
+ requestAnimationFrame(animate);
+}
+
+animate();
--- /dev/null
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8"/>
+ <title>robinkrens.nl - Simple JS PID</title>
+ <link rel="stylesheet" href="styles.css" />
+ <script type="module" src="app.js"></script>
+ </head>
+ <body>
+ <canvas id="area"></canvas>
+ </body>
+</html>