From 07a36f2b38a5cba402ebc5158710f5a85f443456 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 17 Jul 2026 03:10:43 -0400 Subject: Post-stream update --- 2026/games_submissions/ellg/vector.js | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 2026/games_submissions/ellg/vector.js (limited to '2026/games_submissions/ellg/vector.js') diff --git a/2026/games_submissions/ellg/vector.js b/2026/games_submissions/ellg/vector.js new file mode 100644 index 0000000..cf32d81 --- /dev/null +++ b/2026/games_submissions/ellg/vector.js @@ -0,0 +1,64 @@ +export class Vector { + static of([x, y]) { + return new Vector(x, y) + } + + constructor(x, y) { + this.x = x + this.y = y + } + + add(val) { + return new Vector(this.x + val.x, this.y + val.y) + } + + subtract(val) { + return new Vector(this.x - val.x, this.y - val.y) + } + + multiply(scalar) { + return new Vector(this.x * scalar, this.y * scalar) + } + + divide(scalar) { + return new Vector(this.x / scalar, this.y / scalar) + } + + dot(other) { + return this.x * other.x + this.y * other.y + } + + cross(other) { + return this.x * other.y - other.x * this.y + } + + hadamard(other) { + return new Vector(this.x * other.x, this.y * other.y) + } + + length() { + return Math.sqrt(this.x ** 2 + this.y ** 2) + } + + distance(other) { + return this.subtract(other).length() + } + + normalize() { + const length = this.length() + if (length === 0) { + return new Vector(0, 0) + } + return new Vector(this.x / length, this.y / length) + } + + rotateByRadians(radians) { + const cos = Math.cos(radians) + const sin = Math.sin(radians) + return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos) + } + + rotateByDegrees(degrees) { + return this.rotateByRadians((degrees * Math.PI) / 180) + } +} -- cgit v1.3.1