<commit_before>function Lorenz(y) {
    var igloo = Lorenz.igloo;
    this.buffers = {
        tail: igloo.array(),
        index: igloo.array(),
        head: igloo.array()
    };
    this.y = y;
    this.tail = {
        i: 0,
        values: [],
        length: 0
    };
    this.trim(Lorenz.tails);
    this.color = Lorenz.colors[Lorenz.colori++ % Lorenz.colors.length].slice(0);
    this.color[0] = this.color[0] / 255;
    this.color[1] = this.color[1] / 255;
    this.color[2] = this.color[2] / 255;
    this.tick = 0;
}

Lorenz.colori = 0;
Lorenz.colors = [
    [0x8d, 0xd3, 0xc7],
    [0xff, 0xff, 0xb3],
    [0xbe, 0xba, 0xda],
    [0xfb, 0x80, 0x72],
    [0x80, 0xb1, 0xd3],
    [0xfd, 0xb4, 0x62],
    [0xb3, 0xde, 0x69],
    [0xfc, 0xcd, 0xe5],
    [0xd9, 0xd9, 0xd9],
    [0xbc, 0x80, 0xbd],
    [0xcc, 0xeb, 0xc5],
    [0xff, 0xed, 0x6f],
    [0xff, 0xff, 0xff]
];

Lorenz.scale = 1 / 25;
Lorenz.rotation = [1.65, 3.08, -0.93];
Lorenz.rotationd = [0, 0, 0];
Lorenz.translation = [-0.03, -0.07, 1.81];

Lorenz.paused = false;
Lorenz.showHeads = true;
Lorenz.tails = 512;

Lorenz.sigma = 10;
Lorenz.beta = 8 / 3;
Lorenz.rho = 28;

Lorenz.lorenz = function(y, h) {
    var sigma = Lorenz.sigma;
    var beta = Lorenz.beta;
    var rho = Lorenz.rho;
    function f(y) {
        return [sigma * (y[1] - y[0]),
                y[0] * (rho - y[2]) - y[1],
                y[0] * y[1] - beta * y[2]];
    };
    function add3(a, b) {
        return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
    }
    function scale3(v, s) {
        return [v[0] * s, v[1] * s, v[2] * s];
    }
    /* RK4 integration */
    var k1 = f(y);
    var k2 = f(add3(y, scale3(k1, h / 2)));
    var k3 = f(add3(y, scale3(k2, h / 2)));
    var k4 = f(add3(y, scale3(k3, h)));
    var sum = add3(add3(k1, scale3(k2, 2)), add3(scale3(k3, 3), k4));
    return add3(y, scale3(sum, h / 6));
};

Lorenz.igloo = (function() {
    var igloo = new Igloo(document.querySelector('#lorenz'));
    var gl = igloo.gl;
    gl.clearColor(0.1, 0.1, 0.1, 1);
    gl.enable(gl.BLEND);
    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
    var lastlast = null;
    var last = null;
    var lastbuttons = null;
    igloo.gl.canvas.addEventListener('mousemove', function(e) {
        var p = {x: e.pageX, y: e.pageY};
        if (last) {
            var dy = (last.y - p.y);
            var dx = (last.x - p.x);
            if (e.buttons & 4) {
                var scale = 1 / 200;
                if (e.shiftKey)
                    Lorenz.translation[2] += dy * scale;
                else
                    Lorenz.translation[0] += dx * -scale;
                Lorenz.translation[1] += dy * scale;
            } else if (e.buttons) {
                var scale = 1 / 100;
                if (e.shiftKey)
                    Lorenz.rotation[1] += dx * -scale;
                else
                    Lorenz.rotation[2] += dx * scale;
                Lorenz.rotation[0] += dy * scale;
            }
        }
        lastbuttons = e.buttons;
        lastlast = last;
        last = p;
    });
    igloo.gl.canvas.addEventListener('mouseup', function(e) {
        var scale = 1 / 100;
        if (lastlast && !(lastbuttons & 4)) {
            Lorenz.rotationd[2] = (lastlast.x - last.x) * scale;
            Lorenz.rotationd[0] = (lastlast.y - last.y) * scale;
        }
        last = null;
    });
    igloo.gl.canvas.addEventListener('touchmove', function(e) {
        var p = {x: e.touches[0].clientX, y: e.touches[0].clientY};
        console.log(p);
        if (last) {
            var scale = 1 / 100;
            Lorenz.rotation[2] += (last.x - p.x) * scale;
            Lorenz.rotation[0] += (last.y - p.y) * scale;
        }
        lastlast = last;
        last = p;
    });
    igloo.gl.canvas.addEventListener('touchend', function() {
        var scale = 1 / 100;
        if (lastlast) {
            Lorenz.rotationd[2] = (lastlast.x - last.x) * scale;
            Lorenz.rotationd[0] = (lastlast.y - last.y) * scale;
        }
        last = null;
    });
    igloo.gl.canvas.addEventListener('DOMMouseScroll', function(e) {
        Lorenz.scale *= e.detail > 0 ? 0.95 : 1.1;
    });
    igloo.gl.canvas.addEventListener('mousewheel', function(e) {
        Lorenz.scale *= e.wheelDelta < 0 ? 0.95 : 1.1;
    });
    window.addEventListener('keypress', function(e) {
        if (e.which == 'a'.charCodeAt(0))
            Lorenz.addRandom();
        else if (e.which == 'c'.charCodeAt(0))
            Lorenz.addClone();
        else if (e.which == 'C'.charCodeAt(0))
            Lorenz.clearAll();
        else if (e.which == ' '.charCodeAt(0))
            Lorenz.paused = !Lorenz.paused;
        else if (e.which == 'h'.charCodeAt(0))
            Lorenz.showHeads = !Lorenz.showHeads;
    });
    return igloo;
}());

Lorenz.programs = {
    line: Lorenz.igloo.program('tail.vert', 'tail.frag'),
    head: Lorenz.igloo.program('tail.vert', 'head.frag')<commit_msg>Add time element to momentum.<commit_after>function Lorenz(y) {
    var igloo = Lorenz.igloo;
    this.buffers = {
        tail: igloo.array(),
        index: igloo.array(),
        head: igloo.array()
    };
    this.y = y;
    this.tail = {
        i: 0,
        values: [],
        length: 0
    };
    this.trim(Lorenz.tails);
    this.color = Lorenz.colors[Lorenz.colori++ % Lorenz.colors.length].slice(0);
    this.color[0] = this.color[0] / 255;
    this.color[1] = this.color[1] / 255;
    this.color[2] = this.color[2] / 255;
    this.tick = 0;
}

Lorenz.colori = 0;
Lorenz.colors = [
    [0x8d, 0xd3, 0xc7],
    [0xff, 0xff, 0xb3],
    [0xbe, 0xba, 0xda],
    [0xfb, 0x80, 0x72],
    [0x80, 0xb1, 0xd3],
    [0xfd, 0xb4, 0x62],
    [0xb3, 0xde, 0x69],
    [0xfc, 0xcd, 0xe5],
    [0xd9, 0xd9, 0xd9],
    [0xbc, 0x80, 0xbd],
    [0xcc, 0xeb, 0xc5],
    [0xff, 0xed, 0x6f],
    [0xff, 0xff, 0xff]
];

Lorenz.scale = 1 / 25;
Lorenz.rotation = [1.65, 3.08, -0.93];
Lorenz.rotationd = [0, 0, 0];
Lorenz.translation = [-0.03, -0.07, 1.81];

Lorenz.paused = false;
Lorenz.showHeads = true;
Lorenz.tails = 512;

Lorenz.sigma = 10;
Lorenz.beta = 8 / 3;
Lorenz.rho = 28;

Lorenz.lorenz = function(y, h) {
    var sigma = Lorenz.sigma;
    var beta = Lorenz.beta;
    var rho = Lorenz.rho;
    function f(y) {
        return [sigma * (y[1] - y[0]),
                y[0] * (rho - y[2]) - y[1],
                y[0] * y[1] - beta * y[2]];
    };
    function add3(a, b) {
        return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
    }
    function scale3(v, s) {
        return [v[0] * s, v[1] * s, v[2] * s];
    }
    /* RK4 integration */
    var k1 = f(y);
    var k2 = f(add3(y, scale3(k1, h / 2)));
    var k3 = f(add3(y, scale3(k2, h / 2)));
    var k4 = f(add3(y, scale3(k3, h)));
    var sum = add3(add3(k1, scale3(k2, 2)), add3(scale3(k3, 3), k4));
    return add3(y, scale3(sum, h / 6));
};

Lorenz.igloo = (function() {
    var igloo = new Igloo(document.querySelector('#lorenz'));
    var gl = igloo.gl;
    gl.clearColor(0.1, 0.1, 0.1, 1);
    gl.enable(gl.BLEND);
    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
    var lastlast = null;
    var last = null;
    var lastbuttons = null;
    igloo.gl.canvas.addEventListener('mousemove', function(e) {
        e.preventDefault();
        var p = {x: e.pageX, y: e.pageY, t: Date.now() / 1000};
        if (last) {
            var dy = (last.y - p.y);
            var dx = (last.x - p.x);
            if (e.buttons & 4) {
                var scale = 1 / 200;
                if (e.shiftKey)
                    Lorenz.translation[2] += dy * scale;
                else
                    Lorenz.translation[0] += dx * -scale;
                Lorenz.translation[1] += dy * scale;
            } else if (e.buttons) {
                var scale = 1 / 100;
                if (e.shiftKey)
                    Lorenz.rotation[1] += dx * -scale;
                else
                    Lorenz.rotation[2] += dx * scale;
                Lorenz.rotation[0] += dy * scale;
            }
        }
        lastbuttons = e.buttons;
        lastlast = last;
        last = p;
    });
    igloo.gl.canvas.addEventListener('mouseup', function(e) {
        e.preventDefault();
        var scale = 1 / 5000;
        if (lastlast && last && !(lastbuttons & 4)) {
            var dx = lastlast.x - last.x;
            var dy = lastlast.y - last.y;
            var dt = Date.now() / 1000 - lastlast.t;
            Lorenz.rotationd[2] = dx / dt * scale;
            Lorenz.rotationd[0] = dy / dt * scale;
        }
        last = null;
    });
    igloo.gl.canvas.addEventListener('touchmove', function(e) {
        e.preventDefault();
        var p = {
            x: e.touches[0].clientX,
            y: e.touches[0].clientY,
            t: Date.now() / 1000
        };
        if (last) {
            var scale = 1 / 100;
            Lorenz.rotation[2] += (last.x - p.x) * scale;
            Lorenz.rotation[0] += (last.y - p.y) * scale;
        }
        lastlast = last;
        last = p;
    });
    igloo.gl.canvas.addEventListener('touchend', function(e) {
        var scale = 1 / 5000;
        if (lastlast && last) {
            var dx = lastlast.x - last.x;
            var dy = lastlast.y - last.y;
            var dt = Date.now() / 1000 - lastlast.t;
            Lorenz.rotationd[2] = dx / dt * scale;
            Lorenz.rotationd[0] = dy / dt * scale;
        } else {
            Lorenz.addRandom();
        }
        last = null;
    });
    igloo.gl.canvas.addEventListener('DOMMouseScroll', function(e) {
        e.preventDefault();
        Lorenz.scale *= e.detail > 0 ? 0.95 : 1.1;
    });
    igloo.gl.canvas.addEventListener('mousewheel', function(e) {
        e.preventDefault();
        Lorenz.scale *= e.wheelDelta < 0 ? 0.95 : 1.1;
    });
    window.addEventListener('keypress', function(e) {
        e.preventDefault();
        if (e.which == 'a'.charCodeAt(0))
            Lorenz.addRandom();
        else if (e.which == 'c'.charCodeAt(0))
            Lorenz.addClone();
        else if (e.which == 'C'.charCodeAt(0))
            Lorenz.clearAll();
        else if (e.which == ' '.charCodeAt(0))
            Lorenz.paused = !Lorenz.paused;
        else if (e.which == 'h'.charCodeAt(0))
            Lorenz.showHeads = !Lorenz.showHeads;
    });
    return igloo;
}());

Lorenz.programs = {
    line: Lorenz.igloo.program('tail.vert', 'tail.frag'),
    head: Lorenz.igloo.program('tail.vert', 'head.frag')
{'fraction_non_alphanumeric': 0.17258250191864927, 'fraction_numerical': 0.04528012279355334, 'mean_word_length': 1.7645186953062848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1907049', 'n_tokens_mistral': 4272, 'n_tokens_neox': 4010, 'n_words': 822}