Giter Club home page Giter Club logo

tinyvec2.js's Introduction

tinyvec2.js

Tiny 2D vector math library for JavaScript.

Description

tinyvec2.js is a couple-of-lines long vector library designed with readability in mind. I found myself writing something similar many times, either when explaining vector math to my peers, or as part of quick experiments where I did not want to deal with managing dependencies.

While I enjoyed writing vector math functions every single time, sometimes the development momentum of what I really needed to build got lost. I wrote this piece of code so it is less likely happen again.

What is inside?

  • Couple of common vector functions.
  • No heavy abstractions. Vector is an array with 2 elements [x, y].
  • Purity. Meaning no mutation. This is why you maybe do not want to use this library in your game. Some operations create new arrays.
  • Contemporary JavaScript. Use a transpiler of your choice if you need to support older browsers.
  • ES6 module.
  • No validation.
  • No dependencies.

When to use this?

  • You study or teach vector math.
  • You need a quick reminder on how to perform common operations on 2D vectors.
  • You need a 2D vector math library that you can just import as ES6 module.
  • You are building a 2D vector math library and want to start somewhere.

Sample program

import { add, mul, norm } from './tinyvec2.js'

const position = [0, 0]
const direction = [1, 1]
const speed = 20

const velocity = mul(norm(direction), speed)
const updatedPosition = add(position, velocity)

License

MIT

tinyvec2.js's People

Contributors

mfandl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.