Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
LICENSE
index.js
index.mjs
package.json
readme.md
test.js

readme.md

Vector

Super basic vector abstraction based on evanw/lightgl.js

Setup

# Fetch latest from github
npm i thewhodidthis/vector

Usage

import { Vector2d } from '@thewhodidthis/vector'

// Inspect
Object.keys(Vector2d).forEach((k) => {
    console.log(k)
})

Example

import { Vector2d, createVector } from '@thewhodidthis/vector'

// Extend
const myVector = Object.assign({}, Vector2d, {
    get w() {
        return this.x
    },
    get h() {
        return this.y
    },
    min() {
        return Math.min(this.x, this.y)
    },
    max() {
        return Math.max(this.x, this.y)
    },
})

// Expand on
const fromAngle = a => createVector(Math.cos(a), Math.sin(a))
const rand = () => fromAngle(Math.random() * Math.PI * 2)
const lerp = (a, b, fraction) => b.subtract(a).multiply(fraction).add(a)