-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.js
65 lines (55 loc) · 1.67 KB
/
Node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Node {
constructor(x,y,cols,rows,width,height){
this.x = x;
this.y = y;
this.cols = cols;
this.rows = rows;
this.width = width;
this.height = height;
this.f=0;
this.g=0;
this.h=0;
this.neighbors = [];
this.previous = undefined;
this.wall = false;
this.red = 255;
this.green = 255;
this.blue = 255;
this.wall = false;
if (random(1)<0.1){
this.wall = true;
}
}
show(){
var w = this.width / this.cols;
var h = this.height / this.rows;
fill(this.red,this.green,this.blue);
if(this.wall){
fill(0);
}
noStroke()
rect(this.x*w,this.y*h,w-1,h-1);
}
addNeighbors(grid){
var i=this.x;
var j =this.y;
var cols = this.cols;
var rows = this.rows;
if( i < cols -1){
//console.log(`Primer if => i = ${i}, j = ${j} col=${cols} row=${rows}`);
this.neighbors.push(grid[i+1][j]);//derecha
}
if(i>0){
//console.log(`Segundo if => i = ${i}, j = ${j} col=${cols} row=${rows}`);
this.neighbors.push(grid[i-1][j]);//Izqui
}
if(j<rows -1 ){
//console.log(`Tercer if => i = ${i}, j = ${j} col=${cols} row=${rows}`);
this.neighbors.push(grid[i][j+1]);//Abajo
}
if (j>0){
//console.log(`Cuarto if => i = ${i}, j = ${j} col=${cols} row=${rows}`);
this.neighbors.push(grid[i][j-1]);//Arriba
}
}
}