<commit_before>define(['threejs', 'trackball'], function() {
    function initPreview($e, dims) {
        var w = 400; // XXX
        var h = 300; // XXX
        var renderer = new THREE.WebGLRenderer({
            clearAlpha: true
        });
        var camera = new THREE.PerspectiveCamera(45, w / h, 0.1, 10000);
        var scene = new THREE.Scene();

        scene.add(camera);
        camera.position.x = -50;
        camera.position.z = 400;

        var controls = trackball(camera);

        // TODO: controls.handleResize() on window resize

        renderer.setSize(w, h);

        var particleSystem = initParticles(scene, dims);
        var particles = particleSystem.particles;

        renderer.render(scene, camera);

        $e.append(renderer.domElement);

        $(window).on('resize', function() {
            // TODO: update w/h properly
            var w = 400;
            var h = 300;

            camera.aspect = w / h;
            camera.updateProjectionMatrix();

            renderer.setSize(w, h);
        });

        var prevTime;
        var ticks;
        function animate(init, cb) {
            var res = init;

            prevTime = new Date().getTime();
            ticks = 0;

            function anim() {
                var curTime = new Date().getTime();
                ticks += curTime - prevTime;
                prevTime = curTime;

                res = cb(res.vars, ticks);

                execute(res.ops);

                controls.update();

                if(res.playing) requestAnimationFrame(anim);
            }

            anim();
        }

        function execute(ops) {
            ops.forEach(function(op) {
                if(!op) return;

                var o = {
                    on: function() {
                        render(dims, particles, op.coords, 1);
                    },
                    off: function() {
                        render(dims, particles, op.coords, 0);
                    }
                }[op.op]();

            });

            renderer.render(scene, camera);
        }

        return {
            evaluate: function(init, cb) {
                execute(init.ops);

                animate(init, cb);
            }
        };
    }

    function trackball(camera) {
        var controls = new THREE.TrackballControls(camera);

        controls.rotateSpeed = 1.0;
        controls.zoomSpeed = 1.2;
        controls.panSpeed = 0.8;

        controls.noZoom = false;
        controls.noPan = false;

        controls.staticMoving = true;
        controls.dynamicDampingFactor = 0.3;

        return controls;
    }

    function render(dims, particles, coords, alpha) {
        var xDims = dims.x;<commit_msg>Attach trackball control to the right element<commit_after>define(['threejs', 'trackball'], function() {
    function initPreview($e, dims) {
        var w = 400; // XXX
        var h = 300; // XXX
        var renderer = new THREE.WebGLRenderer({
            clearAlpha: true
        });
        var camera = new THREE.PerspectiveCamera(45, w / h, 0.1, 10000);
        var scene = new THREE.Scene();

        scene.add(camera);
        camera.position.x = -50;
        camera.position.z = 400;

        var controls = trackball($e, camera);

        // TODO: controls.handleResize() on window resize

        renderer.setSize(w, h);

        var particleSystem = initParticles(scene, dims);
        var particles = particleSystem.particles;

        renderer.render(scene, camera);

        $e.append(renderer.domElement);

        $(window).on('resize', function() {
            // TODO: update w/h properly
            var w = 400;
            var h = 300;

            camera.aspect = w / h;
            camera.updateProjectionMatrix();

            renderer.setSize(w, h);
        });

        var prevTime;
        var ticks;
        function animate(init, cb) {
            var res = init;

            prevTime = new Date().getTime();
            ticks = 0;

            function anim() {
                var curTime = new Date().getTime();
                ticks += curTime - prevTime;
                prevTime = curTime;

                res = cb(res.vars, ticks);

                execute(res.ops);

                controls.update();

                if(res.playing) requestAnimationFrame(anim);
            }

            anim();
        }

        function execute(ops) {
            ops.forEach(function(op) {
                if(!op) return;

                var o = {
                    on: function() {
                        render(dims, particles, op.coords, 1);
                    },
                    off: function() {
                        render(dims, particles, op.coords, 0);
                    }
                }[op.op]();

            });

            renderer.render(scene, camera);
        }

        return {
            evaluate: function(init, cb) {
                execute(init.ops);

                animate(init, cb);
            }
        };
    }

    function trackball($e, camera) {
        var controls = new THREE.TrackballControls(camera, $e.get()[0]);

        controls.rotateSpeed = 1.0;
        controls.zoomSpeed = 1.2;
        controls.panSpeed = 0.8;

        controls.noZoom = false;
        controls.noPan = false;

        controls.staticMoving = true;
        controls.dynamicDampingFactor = 0.3;

        return controls;
    }

    function render(dims, particles, coords, alpha) {
        var xDims = dims.x;
{'fraction_non_alphanumeric': 0.11427009294696555, 'fraction_numerical': 0.01366867140513942, 'mean_word_length': 1.352336048006858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2317334', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1432, 'n_words': 344}