<commit_before>if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};

TWOPI = Math.PI * 2;

canvas = null;
ctx = null;

width = null;
height = null;

bodies = new Array();

G = 1;
protoDiskSize = null;

// This is called by document.onload
function init() {
    console.log("init");
    canvas = $('#canvas')
    ctx = canvas[0].getContext("2d");

    canvas.after('<div id="stats"></div>');
    $('#stats').append('<span id="numBodies"></span>');

    canvas.after('<form id="controls"></form>');
    $('#controls').append('<input type="checkbox" id="run" checked="checked" />Run</form>');

    width = canvas.width();
    height = canvas.height();
    protoDiskSize = height * 0.5;

    for (var i=0; i<200; i++) {
        var a = Math.random()*TWOPI;
        var m = Math.random() * protoDiskSize;
        var x = Math.cos(a)*m + width/2;
        var y = Math.sin(a)*m + height/2;

        a += Math.PI / 2;
        m = 5;
        var vx = Math.cos(a) * m;
        var vy = Math.sin(a) * m;
        var mass = Math.random()*1+10;
        bodies[i] = new Body(x,y,vx,vy,mass);
    }

    return setInterval(draw,30);
}

timestep = 0.1;
// Main loop
function draw() {
    if ($('#run:checked').val() == null) {
        return;
    }
    ctx.fillStyle = "rgb(0,0,0)";
    ctx.fillRect(0,0,width,height);

    // Calculate gravity forces
    for (var i = 0; i < bodies.length - 1; i++) {
        for (var j = i + 1; j < bodies.length; j++) {
            bodies[i].doGrav(bodies[j]);
        }
    }

    // tick
    for (var i = 0; i < bodies.length; i++) {
        bodies[i].tick(timestep);
    }

    // check collisions
    for (var i = 0; i < bodies.length - 1; i++) {
        for (var j = i + 1; j < bodies.length; j++) {
            if (bodies[i].checkHit(bodies[j])) {
                // remove bodies[j]
                bodies.splice(j,1);
                // counteract the loop's increment
                j--;
            }
        }
    }

    // draw
    for (var i = 0; i < bodies.length; i++) {
        bodies[i].draw();
    }

    $('numBodies').html("Bodies: " + bodies.length);
}

function Body(x,y,vx,vy,mass) {
    this.pos = new Vector().xy(x,y);
    this.oldpos = new Vector().xy(x-vx, y-vy);
    this.accel = new Vector().xy(0,0);

    this.oldt = 1;

    this.mass = mass;
    this.r = Math.log(mass);

    this.doGrav = function(other) {
        var dx = other.pos.x - this.pos.x;
        var dy = other.pos.y - this.pos.y;
        // we dont actually need the distance, just the square
        var distSq = dx*dx + dy*dy;
        var rSq = this.r*this.r + other.r*other.r;

        var fMag = (G*this.mass * other.mass) / distSq;
        var fVec = new Vector().xy(dx, dy);
        fVec.m = fMag;
        fVec.updateXY();

        this.accel = this.accel.add(fVec);
        other.accel = other.accel.add(fVec.times(-1));
        return;
    }<commit_msg>Controls, tweaks.<commit_after>if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};

TWOPI = Math.PI * 2;

canvas = null;
ctx = null;

width = null;
height = null;

bodies = new Array();

G = 1;
protoDiskSize = null;

// This is called by document.onload
function init() {
    console.log("init");
    canvas = $('#canvas')
    ctx = canvas[0].getContext("2d");

    width = canvas.width();
    height = canvas.height();

    ui();

    return setInterval(draw,30);
}

function ui() {
    // add some stats
    canvas.after('<div id="stats"></div>');
    $('#stats').append('<span id="numBodies"></span>');

    // add some controls
    canvas.after('<div><form id="controls"></form></div>');
    // run checkbox
    $('#controls').append('<input type="checkbox" id="run" checked="checked">Run</input>');
    // clear
    $('#controls').append('<input type="button" id="clear" value="Clear" />');
    $('#clear').click(function() {
        bodies.length = 0;
    });
    // protodisk
    $('#controls').append('<input type="button" id="protodisk" value="Generate Disk" />');
    $('#protodisk').click(function() {
        protoDisk();
    });
}

function protoDisk() {
    protoDiskSize = height * 0.45;

    for (var i=0; i<200; i++) {
        var a = Math.random()*TWOPI;
        var m = Math.random() * protoDiskSize;
        var x = Math.cos(a)*m + width/2;
        var y = Math.sin(a)*m + height/2;

        a += Math.PI / 2;
        m = 5;
        var vx = Math.cos(a) * m;
        var vy = Math.sin(a) * m;
        var mass = Math.random()*1+10;
        bodies.push(new Body(x,y,vx,vy,mass));
    }
}

timestep = 0.03;
// Main loop
function draw() {
    if ($('#run:checked').val() == null) {
        return;
    }
    ctx.fillStyle = "rgb(0,0,0)";
    ctx.fillRect(0,0,width,height);

    // Calculate gravity forces
    for (var i = 0; i < bodies.length - 1; i++) {
        for (var j = i + 1; j < bodies.length; j++) {
            bodies[i].doGrav(bodies[j]);
        }
    }

    // tick
    for (var i = 0; i < bodies.length; i++) {
        bodies[i].tick(timestep);
    }

    // check collisions
    for (var i = 0; i < bodies.length - 1; i++) {
        for (var j = i + 1; j < bodies.length; j++) {
            if (bodies[i].checkHit(bodies[j])) {
                // remove bodies[j]
                bodies.splice(j,1);
                // counteract the loop's increment
                j--;
            }
        }
    }

    // draw
    for (var i = 0; i < bodies.length; i++) {
        bodies[i].draw();
    }

    $('#numBodies').html("Bodies: " + bodies.length);
}

function Body(x,y,vx,vy,mass) {
    this.pos = new Vector().xy(x,y);
    this.oldpos = new Vector().xy(x-vx, y-vy);
    this.accel = new Vector().xy(0,0);

    this.oldt = 1;

    this.mass = mass;
    this.r = Math.log(mass);

    this.doGrav = function(other) {
        var dx = other.pos.x - this.pos.x;
        var dy = other.pos.y - this.pos.y;
        // we dont actually need the distance, just the square
        var distSq = dx*dx + dy*dy;
        var rSq = this.r*this.r + other.r*other.r;

        var fMag = (G*this.mass * other.mass) / distSq;
        var fVec = new Vector().xy(dx, dy);
        fVec.m = fMag;
        fVec.updateXY();

        this.accel = this.accel.add(fVec);
        other.accel = other.accel.add(fVec.times(-1));
        return;
    }
{'fraction_non_alphanumeric': 0.1921903599755949, 'fraction_numerical': 0.01235509456985967, 'mean_word_length': 2.1120075937351683, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 23, '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': '2422544', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2285, 'n_words': 524}