Way better gradient Generator

by Darby Rathbone

JavaScript

(function () {
    var RGBparse = function (s) {
        var val = [];
        val = s.split(",");
        var temp = [];
        val.forEach(function (e) {

            e = e.replace(/[^\d]/g, '');
            temp.push(parseFloat(e));
        });
        return temp;
    }
    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,
           ...