Code viewer for World: Binary tree

// Cloned by Jorge Blanco on 18 Oct 2019 from World "Binary tree" by "Coding Train" project 
// Please leave this clone trail here.
 

// Modified port of "01_binary_tree_viz" from AI course by Daniel Shiffman
// https://github.com/nature-of-code/NOC-S17-2-Intelligence-Learning/tree/master/week1-graphs

// Daniel Shiffman
// Nature of Code: Intelligence and Learning
// https://github.com/shiffman/NOC-S17-2-Intelligence-Learning

// canvas size 
const CW = 900;
const CH = 600;
   
const ELLIPSE_SIZE = CW / 25;

const ROOT_X = CW / 2;
const ROOT_Y = CH / 10;

// range of numbers
const MAX = 3000;

// how many nodes 
const NONODES = MAX / 2;

// how many to draw initially 
const NUM_NODES_TO_DRAW = 50;

// console log how we build the tree or not 
const SHOWBUILD = false;

const root_x = CW / 2;
const root_y = CH / 10;

var showPathWhileSearching = true;

// Binary tree
var tree;

function setup() 
{
  createCanvas(CW,CH);
  background(51);

    $.getScript ( "/uploads/9jblanco/node.js", function() {
    
        $.getScript ( "/uploads/9jblanco/tree.js", function() {
        
            var nextRandomValue = function () {
                return floor(random(0, MAX));
            };
            
            tree = new Tree();
       
            // add root and show it 
            tree.addRootValue(nextRandomValue(), root_x, root_y);
            tree.traverse();
      
            // party time
            var searhFor = nextRandomValue();
            var result = tree.search(searhFor, nextRandomValue, showPathWhileSearching);
            if (result === null)  {
                  AB.msg('Searching for: ' + searhFor + ' ->not found', 2);
            }
            else {
                  AB.msg('Searching for: ' + searhFor + ' ->found', 2);
            }
        } );
    } );
}