Triangle Gradient

creates a gradient between 3 points and 3 colors

JavaScript

(function () {
    var Vector = (function () {
        function Vector(x, y) {
            this.x = x;
            this.y = y;
            this.prevmag = 1;

        }
        return Vector;
    })();
    Vector.prototype = {
        toString: function () {
            return "[" + this.x + "," + this.y + "]";
        },
        mag: function () {
            return Math.sqrt((this.x * this.x) + (this.y * this.y));
        },
        mult: function (k) {
            this.x = this.x * k;
            this.y = this.y * k;
            return this.toString();
        },
        div: function (k) {
            this.x = (this.x) / (k);
            this.y = (this.y) / (k);
            return this.toString();
        },
        norm: function () {
            this.prevmag = this.mag();
            this.div((this.mag()));
            return this.toString();
        },
        add: function (vk) {
            this.x = this.x + vk.x;
            this.y = this.y + vk.y;
            return this.toString();
        },
        sub: function (vk) {
            this.x = this.x - vk.x;
            this.y = this.y - vk.y;
            return this.toString();
        },

        direction: function () {
            return Math.atan2(this.y, this.x);
        },
        dot: function (v1) {
            return (v1.x * this.x) + (v1.y * this.y);
        },
        dist: function (other) {
            return Math.sqrt((this.x - other.x) * (this.x - other.x) + (this.y - other.y) * (this.y - other.y));
        }
    };

    var intsec = function (p1, p2, p3, p4) {
        var x1 = p1.x,
            y1 = p1.y,
            x2 = p2.x,
            y2 = p2.y,
            x3 = p3.x,
            y3 = p3.y,
            x4 = p4.x,
            y4 = p4.y;
        return new Vector((((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4))), (((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 -...