const choosePixelsSize = require('../penSize/choosePenSize');
const currColorWrapper = document.querySelector('.curr-icon');
function fillArea(topIndex, leftIndex, cells, cellsInRow) {
window.console.log(leftIndex);
const currPixelIndex = topIndex + leftIndex;
const currPixels = choosePixelsSize(cells, topIndex, leftIndex, currPixelIndex, cellsInRow);
for (let i = 0; i < currPixels.length; i += 1) {
if (currPixels[i]) {
currPixels[i].curcolor = `${currColorWrapper.style.backgroundColor}`;
currPixels[i].fill(`${currColorWrapper.style.backgroundColor}`);
}
}
}
export default function drawStroke(startX, startY, pX, pY, cellH, cellsInRow, cellW, cells) {
let startPointX = startX;
let startPointY = startY;
const currPointX = Math.floor(pX / cellH) * cellsInRow;
const currPointY = Math.floor(pY / cellW);
// for (let i = 0; i < cells.length; i += 1) {
// const cell = cells[i];
// if (cell) {
// cell.curcolor = 'rgb(112, 112, 112)';
// cell.fill('rgb(112, 112, 112)');
// cell.drawBorder('rgb(168, 168, 168)');
// }
// }
if (startX < currPointX && startPointY < currPointY) {
while (startPointX !== currPointX && startPointY !== currPointY) {
startPointX += cellsInRow;
startPointY += 1;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX > currPointX && startPointY > currPointY) {
while (startPointX !== currPointX && startPointY !== currPointY) {
startPointX -= cellsInRow;
startPointY -= 1;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX < currPointX && startPointY === currPointY) {
while (startPointX !== currPointX) {
startPointX += cellsInRow;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX === currPointX && startPointY < currPointY) {
while (startPointY !== currPointY) {
startPointY += 1;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX > currPointX && startPointY === currPointY) {
while (startPointX !== currPointX) {
startPointX -= cellsInRow;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX === currPointX && startPointY > currPointY) {
while (startPointY !== currPointY) {
startPointY -= 1;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
if (startX > currPointX && startPointY < currPointY) {
while (startPointY !== currPointY) {
startPointX -= cellsInRow;
startPointY += 1;
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}
}
const cell = {
top,
left,
curcolor: 'rgb(112, 112, 112)',
fill(color) {
context.fillStyle = color;
context.fillRect(this.top, this.left, cellWidth, cellHeight);
},
drawBorder(boderColor) {
context.beginPath();
context.strokeStyle = boderColor;
context.moveTo(this.top - 0.5, this.left - 0.5);
context.lineTo(this.top - 0.5, this.left + cellWidth - 0.5);
context.lineTo(this.top + cellHeight - 0.5, this.left + cellWidth - 0.5);
context.lineTo(this.top + cellHeight - 0.5, this.left - 0.5);
context.lineTo(this.top - 0.5, this.left - 0.5);
context.stroke();
},
getTop() {
return this.top;
},
getLeft() {
return this.left;
},
};
let startPointX = startX; - начальная точка столбца
let startPointY = startY; - начальная точка строки
const currPointX = Math.floor(pX / cellH) * cellsInRow; - текущаяя точка столбца
const currPointY = Math.floor(pY / cellW); - текущаяя точка строки
if (startX < currPointX && startPointY < currPointY) {
while (startPointX !== currPointX && startPointY !== currPointY) {
startPointX += cellsInRow;
startPointY += 1;
window.console.log(startPointY);
fillArea(startPointX, startPointY, cells, cellsInRow);
}
}