JSFiddle - React, Tailwind, and code Playground

by blackmiaool

HTML

<canvas id="cav" width="600" height="400"></canvas>

JavaScript

console.clear();
function Neuron(brain, layer) {
    var that = this;
    brain.counter++;
    brain.globalReferenceNeurons[brain.counter] = this;
    this.active = true; //as the brain mutates, some neurons and 
    //connections are disabled via this property
    this.layer = layer;
    this.id = brain.counter;
    this.connected = {};
    this.connections = {};
    this.connect = function (target) {
        if (that.active == true) {
            new Connection(brain, this, target, function (id, connection) {
                brain.globalReferenceConnections[id] = connection;
                that.connections[id] = connection;
            });
        }
    };
}

function Connection(brain, source, target, callback) {
    if (source.layer < target.layer) {
        brain.counter++;
        brain.globalReferenceConnections[brain.counter] = this;
        this.active = true; //as the brain mutates, some neurons and 
        //connections are disabled via this property
        this.id = brain.counter;
        this.source = source;
        this.target = target;
        target.connected[this.id] = this;
        callback(this.id, this);
    }
}


function renderBrain(brain, context, canvas) {
    context.clearRect(0, 0, canvas.width, canvas.height);
    var width = canvas.width;
    var height = canvas.height;
    var layers = brain.layers;
    var heightDivision = height / layers;
    var layerList = [];
    for (var i1 = 0; i1 < brain.layers; i1++) {
        layerList.push([]);
        for (var prop1 in brain.globalReferenceNeurons) {
            if (brain.globalReferenceNeurons[prop1].layer === i1) {
                layerList[i1].push(brain.globalReferenceNeurons[prop1]);
            }
        }
    }

    function renderLayer(layer, layerCount, layerTotal) {
        var length = layer.length;
        var widthDivision = width / length;
        var neuronCount = 0;
        for (var i1 = 0; i1 < layer.length; i1++) {
            neuronCount++;
            const...