-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.js
147 lines (121 loc) · 3.06 KB
/
cell.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//each cell here
var Cell=function(x,y,i){
this.x=y;
this.y=x;
this.index=i;
this.previous=undefined;
this.weight=0;
this.currentWeight=Infinity;
this.draw=function(){
this.X=this.x*size;
this.Y=this.y*size;
c.beginPath();
c.strokeStyle="#e3e3e3";
c.rect(this.X,this.Y,size,size);
c.stroke();
}
//block cell design
this.roadBlock=function(x,y,i){
this.X=x;
this.Y=y;
c.beginPath();
c.fillStyle="black";
c.strokeStyle="#353836";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
//Text on Block
// c.font=fontSize;
// c.fillStyle="white";
// c.fillText(i,this.X+textXpostion,this.Y+(size/3));
// console.log(this.X+","+this.Y);
}
//end path cell design
this.endPath=function(x,y,i){
this.X=x;
this.Y=y;
c.beginPath();
c.fillStyle="red";
c.strokeStyle="white";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
//Text on Block
// c.font=fontSize;
// c.fillStyle="white";
// c.fillText(this.currentWeight,this.X+textXpostion,this.Y+(size/3));
// console.log(this.X+","+this.Y);
}
//start path cell design
this.startPath=function(x,y,i){
this.X=x;
this.Y=y;
c.beginPath();
c.fillStyle="green";
c.strokeStyle="white";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
//Text on Block
// c.font=fontSize;
// c.fillStyle="white";
// c.fillText(this.currentWeight,this.X+textXpostion,this.Y+(size/3));
// console.log(this.X+","+this.Y);
}
//path design
this.path=function(){
c.beginPath();
c.strokeStyle="white";
c.fillStyle="#5db073";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
// //Text on Block
// c.font=fontSize;
// c.fillStyle="black";
// c.fillText(this.index,this.X+35,this.Y+(size/2));
// //console.log(this.X+","+this.Y);
}
this.checkingCell=function(){
c.beginPath();
c.strokeStyle="white";
c.fillStyle="#66c0e3";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
// c.font=fontSize;
// c.fillStyle="black";
// c.fillText(this.previous+","+this.currentWeight,this.X+textXpostion,this.Y+(size/2));
}
this.smallestWeight=function(){
c.beginPath();
//c.strokeStyle="white";
c.fillStyle="#c6e625";
c.rect(this.X,this.Y,size,size);
c.fill();
//c.stroke();
}
this.visitedCellColor=function(){
c.beginPath();
var grd = c.createLinearGradient(startCell.x, startCell.y, endCell.x, endCell.y);
grd.addColorStop(0, "#42d7f5");
grd.addColorStop(0.5, "#42a7f5");
grd.addColorStop(1, "#266dc9");
c.strokeStyle="white";
c.fillStyle=grd;
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
// c.font=fontSize;
// c.fillStyle="black";
// c.fillText(this.previous+","+this.currentWeight,this.X+textXpostion,this.Y+(size/2));
}
this.finalPath=function(){
c.beginPath();
c.strokeStyle="white";
c.fillStyle="blue";
c.rect(this.X,this.Y,size,size);
c.fill();
c.stroke();
}
}