<commit_before>
// storing the values to loop around a cell
let neighbors = [
    [-1,-1],[-1, 0],[-1, 1],
    [ 0,-1],/*[00]*/[ 0, 1],
    [ 1,-1],[ 1, 0],[ 1, 1]
]

// board size
let width = 6;
let height = 6;

// initialize blank board
let board = (new Array(height)).fill((new Array(width).fill(true)));

// store the target cell opacity for mouseover
let changeto = 1;

// create canvas and fetch imageData 
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
var imageData = context.getImageData(0, 0, canvas.width, canvas.height);

// calculate canvas
function draw(board) {
    let data = imageData.data;
    let length = data.length;
    let w = canvas.width;
    let h = canvas.height;
    for (let i = 0; i < length; ++i) {
        let j = i/4 >> 0;
        let color = board[j/w/h*height>>0][j%w/w*width>>0]?0:255;
        data[i] = color; ++i;
        data[i] = color; ++i;
        data[i] = color; ++i;
        data[i] = 255;
    }
    context.putImageData(imageData, 0, 0);
}

board = reset(board);
draw(board);

window.onclick =  function() {
    console.log('gen');
    let newboard = gen(board);
    board = newboard;
    draw(newboard);
}

/*let count = 500;
function genloop() {
    draw(board);
    board = reset(board);
    if (count !== 0) {
        --count;
        requestAnimationFrame(genloop);
    }
}
genloop();*/

// loop over all cells
function map2d(store, eval) {
    let temp = store.slice();
    for (let i = 0; i < height; ++i) {
        temp[i] = temp[i].slice();
        for (let j = 0; j < width; ++j) {
            temp[i][j] = eval(i, j, store);
        }
    }
    return temp;
}

// calculate the new generation
function gen(board) {
    return map2d(board, (i, j, store) => {
        let count = 0;
        for (let k = 0; k < neighbors.length; ++k) {
            let m = neighbors[k][0]+i;
            let n = neighbors[k][1]+j;
            if (m < 0 || m >= height || n < 0 || n >= width) {
                continue;
            }
            count += +board[m][n];
        }
        if (board[i][j]) {
            if (count === 2 || count === 3) {
                return true;
            } else {
                return false;
            }
        } else {
            if (count === 3) {
                return true;
            } else {
                return false
            }
        }
    });
}

// randomize board
function reset(board) {<commit_msg>drawing with rectangles and performance boost<commit_after>
// storing the values to loop around a cell
let neighbors = [
    [-1,-1],[-1, 0],[-1, 1],
    [ 0,-1],/*[00]*/[ 0, 1],
    [ 1,-1],[ 1, 0],[ 1, 1]
]

// board size
let width = 60;
let height = 60;

// initialize blank board of HEIGHTxWIDTH
let board = (new Array(height)).fill(new Array(width));

// store the target cell opacity for mouseover
let changeto = 1;

// create canvas and fetch imageData 
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');

window.onclick =  function() {
    let newboard = gen(board);
    board = newboard;
    draw(newboard);
}

let count = 500;
function genloop() {
    board = gen(board);
    draw(board);
    if (count !== 0) {
        --count;
        requestAnimationFrame(genloop);
    }
}
board = reset(board)
genloop();

// draws cells to canvas with fillRect
function draw(board) {
    let cellheight = canvas.height/height >> 0;
    let cellwidth = canvas.width/width >> 0;
    let m = height-1;
    while (m + 1) {
        let n = width-1;
        let verticalpos = m*cellheight;
        while (n + 1) {
            context.fillStyle = board[m][n]?'black':'white';
            context.fillRect(verticalpos, n*cellwidth, cellheight, cellwidth);
            --n;
        }
        --m;
    }
}

// map over all cells of the internal board
function map2d(store, eval) {
    let temp = store.slice();
    let m = height-1;
    while (m + 1) {
        temp[m] = temp[m].slice();
        let n = width-1;
        while (n + 1) {
            temp[m][n] = eval(m, n, store);
            --n;
        }
        --m;
    }
    return temp;
}

// calculate the new generation
function gen(board) {
    return map2d(board, (i, j, store) => {
        let count = 0;
        let o = neighbors.length-1;
        while (o + 1) {
            let m = neighbors[o][0]+i;
            let n = neighbors[o][1]+j;
            --o;
            if (m < 0 || m >= height || n < 0 || n >= width) {
                continue;
            }
            count += +board[m][n];
        }
        if (board[i][j]) {
            if (count === 2 || count === 3) {
                return true;
            } else {
                return false;
            }
        } else {
            if (count === 3) {
                return true;
            } else {
                return false
            }
        }
    });
}

// randomize board
function reset(board) {
{'fraction_non_alphanumeric': 0.15858132898491642, 'fraction_numerical': 0.021402364451691806, 'mean_word_length': 1.7645070422535212, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '2430621', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1582, 'n_words': 460}