cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              /*Neural Network Visualization
Peter Farrell
May 30, 2017
*/

var nodeList = [];
var node2List = []; //second column of hidden nodes
var inList = [];
var outList = [];
var pathList = [];

function setup(){
    createCanvas(600,600);
   //Nodes
    for(var i=0; i<4; i++){
        nodeList.push(new Node(220,100+150*i))
    }
  //Nodes2
  for(var i=0; i<4; i++){
        node2List.push(new Node2(380,100+150*i))
    }
    for(var j=1; j< 4; j++){
        inList.push(new Input(150*j+25))
    }
  for (var j = 0; j<2; j++){
        outList.push(new Output(250+150*j));
    }
  //Paths from inputs to hidden1
    for (var n=0; n<inList.length; n++){ 
        for (var h=0; h<nodeList.length; h++){ 
            pathList.push(new Path(inList[n],nodeList[h],false));
        }
    }
  //Paths between hidden nodes
  for (var n=0; n<nodeList.length; n++){ 
        for (var h=0; h<node2List.length; h++){ 
            pathList.push(new Path(nodeList[n],node2List[h],false));
        }
    }
  //Paths from hidden2 to outputs
    for (var h=0; h<node2List.length; h++){  
        for(var o=0; o<outList.length; o++){ 
            pathList.push(new Path(node2List[h],outList[o],false));
        }
    }
}
   
    
function draw(){
    background(0)
    for (var p=0; p<pathList.length; p++){
        pathList[p].update();
      }
    for (var h=0; h<nodeList.length; h++){
        nodeList[h].update();
    }
  for (var h=0; h<node2List.length; h++){
        node2List[h].update();
    }
    for (var n=0; n<inList.length; n++){ 
        inList[n].update(nodeList,node2List,outList,pathList);
    }
    for (var o=0; o<outList.length; o++){
        outList[o].update();
    }
    
    }
        
function Node(x,y){
        this.x = x;
        this.y = y;
        this.sz = 40;
        this.col = color(255);
        this.energy = 0;
        
    this.update = function(){
        
        fill(this.col);
        noStroke();
        
        ellipse(this.x,this.y,this.sz,this.sz)
    }
}

function Node2(x,y){
        this.x = x;
        this.y = y;
        this.sz = 40;
        this.col = color(255);
        this.energy = 0;
        
    this.update = function(){
        
        fill(this.col);
        noStroke();
        
        ellipse(this.x,this.y,this.sz,this.sz)
    }
}
function Input(y){
        this.col = color(237,168,93);
        this.x = 70;
        this.y = y;
        this.sz = 40;
        this.energy = 0;
        
    this.update = function(nodeList,node2List,outList,pathList){
        //this.col = color(237,168,93);
        fill(this.col);
        noStroke();
        
        ellipse(this.x,this.y,this.sz,this.sz);
        if (mouseIsPressed){
            if (dist(mouseX,mouseY,this.x,this.y) < this.sz){
                var hidden = int(random(nodeList.length));
              var middle = int(random(node2List.length));
                var out = int(random(outList.length));
                pathList.push(new Path(node2List[middle],outList[out],true));
              pathList.push(new Path(nodeList[hidden],node2List[middle],true));
                pathList.push(new Path(this,nodeList[hidden],true));
            }
            }
    }
}
                
        
function Output(y){
        //this.col = color(93,168,237);
        this.x = 530;
        this.y = y;
        this.sz = 40;
        this.energy = 0;
        this.col = color(93,168,237);//this.energy%255);
        
    this.update = function(){
        this.col = color(93,168,237);//this.energy%255);
        fill(this.col);
        noStroke();
        
        ellipse(this.x,this.y,this.sz,this.sz)
        if (mouseIsPressed){
            if (dist(mouseX,mouseY,this.x,this.y) < this.sz){
                this.energy += 10;
                this.col = color(93,168,this.energy%255);
                }
            }
    }
}
    
function Path(node1,node2,clicked){
        this.node1 = node1
        this.node2 = node2
        this.energy = random(10)
        this.clicked = clicked
        this.clickedTime = 10
        
    this.update = function(){
        stroke(255,255,0)
        if (this.clicked){
          this.energy ++;
            this.clickedTime -= 1
            if (this.clickedTime == 0){
                this.clicked = false;
            }
            strokeWeight(this.clickedTime);
        }
        else{
            strokeWeight(this.energy/5)
        }
        line(this.node1.x,this.node1.y,
             this.node2.x,this.node2.y)
        
    }
}
        
        
            
          
!
999px
Loading ..................

Console