Code viewer for World: Binary tree (clone by Akshara)

// Cloned by Akshara on 29 Oct 2020 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

//......1........ declaring canvas width(cw) and canvas height(ch)
const cw = 900;
const ch = 900;

// ......2.........decalaring positions along X axis(root_x) and Y axis(root_y) for the root node.
//..................Also declaring the size of the nodes, for display(ellipse_size)

const root_x = cw / 2;
const root_y = ch / 10;
const ellipse_size = cw / 25;

// ......3.........range of numbers
const MAX = 30;

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

//......5........console log on whether we build the tree or not
const SHOWBUILD = true;

//.......6.......Declare the binary tree
var tree;

function setup()
{
    createCanvas(cw,ch);
    
$.getScript ("/uploads/codingtrain/node.js", function() {
$.getScript ("/uploads/codingtrain/tree.js", function() {
        
    tree = new Tree();
    console.log('=======Building-Tree========');
    for(var i=0;i<NONODES;i++)
    {
        var n = floor(random(0,MAX));
        tree.addValue(n);
    }
    
    background('lightblue');
    tree.traverse();
    
    
    //............search the tree for random number
    var x = floor(random(0,MAX));
    AB.msg('the console shows how we sorted through the tree <br> The the value of the node being searched is:' + x +'<br>');
    console.log( "=== search tree for " + x  + " ===================");
    var result = tree.search(x);
    if (result === null) AB.msg('The Node' + x + 'was not found', 2);
    else AB.msg('The Node' + x + 'was not found', 2);
} );
        
} );
}