import { state } from './state.js'; import { normalizeAngle } from './math.js'; export class Physics { constructor(config) { this.config = config; state.angularAcceleration = config.angularAcceleration; } update(deltaTime) { // Update angular velocity state.angularSpeed += state.angularAcceleration * deltaTime; state.angle += state.angularSpeed * deltaTime; state.angle = normalizeAngle(state.angle); // Calculate position state.squareX = state.canvasWidth / 2 + Math.cos(state.angle) * this.config.radius; state.squareY = state.canvasHeight / 2 + Math.sin(state.angle) * this.config.radius; // Calculate actual velocity components in pixels per second state.velocity.x = -Math.sin(state.angle) * state.angularSpeed * this.config.radius; state.velocity.y = Math.cos(state.angle) * state.angularSpeed * this.config.radius; } }