-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillBucket.js
47 lines (38 loc) · 1.19 KB
/
fillBucket.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
class FillBucket {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
this.pixelStack = [];
this.width = $tempCanvas.width;
}
getPosition(x, y) {
this.temp = [];
this.temp.push(x);
this.temp.push(y);
this.pixelStack.push(this.temp);
this.getNewPosition(this.pixelStack);
};
displayPosition() {
// console.log(this.pixelStack.pop());
// console.log(this.newPos)
console.log(this.x, this.y);
console.log(this.pixelData);
};
getNewPosition(pixelStack) {
while (pixelStack.length) {
this.newPos = pixelStack.pop();
this.x = this.newPos[0];
this.y = this.newPos[1];
this.pixelData = this.context.getImageData(0, 0, $canvas.width, $canvas.height);
this.colorIndex = this.getColorIndicesForCoord(this.x, this.y, this.width);
// this.pixelPos = (this.y * 960 + this.x) * 4;
// while (this.y-- >= 0 && this.matchStartColor(this.pixelPos)) {
// this.pixelPos -= 960 * 4;
// }
}
};
getColorIndicesForCoord(x, y, width) {
this.red = this.y * (this.width * 4) + this.x * 4;
return [this.red, this.red + 1, this.red + 2, this.red + 3];
};
};