Code viewer for World: Binary tree (clone by anis...

// Cloned by anish kumar on 23 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

// canvas size 
const cw = 1200;
const ch = 900;
   
const root_x = cw / 2;
const root_y = ch / 10;
const ellipse_size = cw / 25;

// range of numbers
const MAX = 999;

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

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


// Binary tree
var tree;


function setup() 
{
    
  var time1 = Date.now();
  //AB.msg("<br> Start time : " + time1, 6);
  //createCanvas(cw,ch);
  AB.msg("<p style=\"background-color:DodgerBlue;\"> <b>See Console log for detailed tree structure</b>", 1 );
  AB.msg("<br> Max range of numbers : " + MAX, 2);
  AB.msg("<br>Number of nodes : " + NONODES, 3);
  

$.getScript ( "/uploads/anish85/node.js", function() {
    console.log ("Got node");
    
$.getScript ( "/uploads/anish85/tree.js", function() {
        console.log ("Got tree");
        
        
  // New tree
  tree = new Tree();

  console.log ("=== build tree =================");
  // Add random values
  for (var i = 0; i < NONODES; i++) 
  {
      var n = floor(random(0, MAX));
      console.log ("adding node: " + n);
      tree.addValue(n);
  }

  background("white");

  // Traverse the tree
  tree.traverse();
  

  // Search the tree for random number 
  var x = floor(random(0, MAX));
  AB.msg( "<br><br> Lets search this tree now for a random number " + x + "<br>", 4 );
  console.log ( "=== search tree for " + x  + " ===================");
   
  var result = tree.search(x);
  if (result == null)   AB.msg("<p style=\"background-color:Tomato;\"> Sorry! " + x + " was not found", 5);
  else                  AB.msg("<p style=\"background-color:LightGreen;\"> Voila! " + x + " was found", 5);
  
  var time2 = Date.now();
  //AB.msg("<br> End time : " + time2, 7);
  time_diff = time2-time1
  AB.msg("<p style=\"background-color:Yellow;\"> Time taken to search: " + time_diff + " milliseconds", 6);
} );
} );

}