var width; // Canvas width in x-axis var length; // Canvas length in y-axis var raw_file; var id_list = new Array(0); // To use number to keep track what id we have var vertex_arr = new Array(0); // Array of vertex in vertex class var edge_arr = new Array(0); // Array to store edge var title = "Facebook ID Connections"; var numNodes; var k; function preload(){ raw_file = loadStrings('edges_v2.txt'); } function setup(){ width = 1000; length = 1000; createCanvas(width, length); for(var i=0; i width-120) return width-120; return netX; } function adjust_netY(orgY,disp_y){ var netY = orgY + disp_y/500; if (netY < 120) return 120; else if (netY > length-120) return length-120; return netY; } class vertex{ constructor(name){ this.x = Math.floor(Math.random()*width); this.y = Math.floor(Math.random()*length); this.disp_x = 0; this.disp_y = 0; this.netX = 0; this.netY = 0; this.name = name; while(this.x <120 || this.x > width-120){ this.x = Math.floor(Math.random()*width); } while(this.y <120 || this.y > length-120){ this.y = Math.floor(Math.random()*length); } } resetDisp(){ this.disp_x =0; this.disp_y =0; } // For making sure disp_x and disp_y is 0, after the initial position is randomize addDisp_x(num){ this.disp_x += num; } addDisp_y(num){ this.disp_y += num; } // To add disp_x and disp_y setDisp_x(num){ this.disp_x = num; } setDisp_y(num){ this.disp_y = num; } setNetX(numX){ this.netX = numX; } setNetY(numY){ this.netY = numY; } getX(){ return this.x; } getY(){ return this.y; } get_dispX(){ return this.disp_x; } get_dispY(){ return this.disp_y; } get_netX(){ return this.netX; //return this.x + this.disp_x/500; } get_netY(){ return this.netY; //return this.y + this.disp_y/500; } getName(){ return this.name; } } class edge{ constructor(v1,v2){ this.v1 = v1; this.v2 = v2; } get_v1(){ return this.v1; } get_v2(){ return this.v2; } } function f_ax(x){ return ((x^2)/k); } function f_rx(x){ //print(sq(k)/x) return (sq(k)/x); } function draw(){ background(255); push(); textSize(22); text(title,width*.4,30); pop(); // Put the title of the graph for (var j=0; j0){ ellipse(vertex_arr[k].get_netX(),vertex_arr[k].get_netY(), 20,20); k--; } // Draw the nodes before the i-th element in the loop pop(); } // If there is no interaction else{ push(); ellipse(vertex.get_netX(),vertex.get_netY(), 20,20); pop(); } } // Draw the nodes }