xxxxxxxxxx
47
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let network
function setup() {
createCanvas(640, 360);
network = new Network(width/2, height/2);
// Create a bunch of Neurons
let a = new Neuron(-280, 0);
let b = new Neuron(-150, 0);
let c = new Neuron(0, 75);
let d = new Neuron(0, -75);
let e = new Neuron(150, 0);
let f = new Neuron(280, 0);
// Connect them
network.connect(a,b,1);
network.connect(b,c,random(0.000000001,1));
network.connect(b,d,random(0.000000001,1));
network.connect(c,e,random(0.000000001,1));
network.connect(d, e,random(0.000000001,1));
network.connect(e, f,1);
// Add them to the Network
network.addNeuron(a);
network.addNeuron(b);
network.addNeuron(c);
network.addNeuron(d);
network.addNeuron(e);
network.addNeuron(f);
}
function draw() {
background(220);
network.update();
network.display();
if (frameCount % 30 == 0) {
network.feedforward(random(1));
}
}