GithubHelp home page GithubHelp logo

ashe-dolinsky-old / plumbing.lua Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 260 KB

plumbing.lua is a multi-purpose library that incorporates easy input-output chaining (piping).

License: MIT License

Lua 100.00%

plumbing.lua's Introduction

plumbing.lua

plumbing.lua is a multi-purpose library that incorporates easy input-output chaining (piping). As an example it makes vector operations a lot more readable. At the moment only raw vector operations are supported, more will follow in time. Uses and is heavily inspired by underscore.lua through a fork that I made, get it here: https://github.com/alex-dolinsky/underscore.lua

single vector operations
  • vec_len : returns a scalar, the vector's length.
  • normalize : returns a normalized vector.
  • vec_id : returns a copy of a vector, which is a different object that contains the same members (shallow copy).
  • vec_ord_perm : returns ordered permutations for a vector as a vector. Example: {1,2,3} => {{1,2,3}, {3,1,2}, {2,3,1}}
single vector and a scalar operations
  • vec_smult : returns a vector multiplied by a scalar, the order of arguments is irrelevant.
multiple vector operations, each of these returns a single vector
  • vec_add : a sum
  • vec_sub : a difference
  • vec_mult : a product
  • vec_div : a quotient
  • vec_cart_prod : returns a Cartesian product of multiple vectors as a vector. Example: {1,2}, {3,4}, {5,6} => {{1,3,5}, {1,3,6}, {1,4,5}, {1,4,6}, {2,3,5}, {2,3,6}, {2,4,5}, {2,4,6}}
utility operations, only in piping!
  • unpack : a multiple return of every member in a vector.

Usage

  • piping: plumbing ({1,2,3}) : vec_add ({9,2,3}, {5,3,1}) : vec_smult (7) : normalize () : unpack () or .output
  • functional: plumbing.vec_add ({9,2,3}, {5,3,1})
  • a cool MOAI/Hanappe example: body:setLinearVelocity(plumbing ({layer : wndToWorld (event.x, event.y)}) : vec_sub ({body : getPos ()}) : normalize() : vec_smult (speed) : unpack())

Links

plumbing.lua's People

Contributors

ashe-dolinsky-old avatar

Watchers

 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.