Git Product home page Git Product logo

pcl's Introduction

PCL

Procedural Content Library

Building From Source

First, clone the repository:

git clone https://github.com/grind086/PCL.git

Then enter the repository directory (/PCL) and run the following. Requires node and npm.

npm install
node build.js

The files PCL.js and PCL.min.js will be created in /build. It is also possible to generate documentation from the source comments using yuidoc.

npm install yuidoc
yuidoc ./src

By default this will generate documentation files in /out, simply open /out/index.html. Note that some files may not be fully documented yet.

pcl's People

Contributors

grind086 avatar

Watchers

 avatar  avatar

pcl's Issues

Simple tweening support

Starting point (from another project):

var Tween = function( list, attributes ) {
    // this.easing = Tween.LINEAR;

    this._easing = Tween.LINEAR;
    this._easefn = this.lerp;

    this._attr  = attributes;
    this._steps = [];
    this._time  = 0;

    for (var i = 0; i < list.length; i++) {
        this.addStep( list[i] );
    }
};

Tween.LINEAR = 0;
Tween.CUBIC  = 1;
Tween.SINE   = 2;
Tween.CUSTOM = 99;

Object.defineProperty(Tween.prototype, 'easing', {
    get: function() { return this._easing; },
    set: function( type, fn ) {
        switch (type) {
            case Tween.CUBIC:
                this._easing = Tween.CUBIC;
                this._easefn = this.cubp;
                break;
            case Tween.SINE:
                this._easing = Tween.SINE;
                this._easefn = this.sinp;
                break;
            case Tween.CUSTOM:
                if (typeof fn == 'function') {
                    this._easing = Tween.CUSTOM;
                    this._easefn = fn;
                    break;
                }
            default:
                this._easing = Tween.LINEAR;
                this._easefn = this.lerp;
        }
    }
});

Tween.prototype.lerp = function( a, b, alpha ) {
    return a * (1 - alpha) + b * alpha;
};

Tween.prototype.cubp = function( a, b, alpha ) {
    alpha = (-2 * alpha + 3) * alpha * alpha;
    return this.lerp( a, b, alpha );
};

Tween.prototype.sinp = function( a, b, alpha ) {
    // return (a - b) / 2 * (Math.cos(Math.PI * alpha) - 1) + a;
    alpha = 0.5 * Math.sin( (alpha - 0.5) * Math.PI ) + 0.5;
    return this.lerp( a, b, alpha );
};

Tween.prototype.addStep = function( step ) {
    if (step.length !== 2) {
        console.error( "Invalid Tween step" );
        return;
    }

    for (var i = 0; i < this._steps.length; i++) {
        if (this._steps[i][0] > step[0]) {
            this._steps.splice( i, 0, step );
            return;
        }
    }

    this._steps.push( step );
};

Tween.prototype.value = function( time ) {
    if ( typeof time != 'number' ) {
        time = this._time;
    }

    if ( time <= this._steps[0][0] ) {
        return this._steps[0][1];
    }

    if ( time >= this._steps[ this._steps.length - 1 ][0] ) {
        return this._steps[ this._steps.length - 1 ][1];
    }

    for (var i = 1; i < this._steps.length; i++) {

        if ( time === this._steps[i][0] ) {
            return this._steps[i][1];
        }

        if ( time < this._steps[i][0] && time > this._steps[i - 1][0] ) {

            var start = this._steps[i - 1],
            end   = this._steps[i],
            alpha = ( time - start[0] ) / ( end[0] - start[0] );

            var value = {};

            for (var i = 0, a; i < this._attr.length; i++) {
                a = this._attr[i];
                value[a] = this._easefn(start[1][a], end[1][a], alpha);
            }

            return value;

        }
    }

    return {};
};

Tween.prototype.update = function( dt ) {
    this._time += dt;
    return this.value( this._time );
};

The timing functions may be unnecessary.

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.