I'm trying to create a rectangle using Javascript, avoiding using canvas functions like moveto and drawto. But my rectangle does not look good. Here is the code:
function retangulo(x1, y1, x2, y2){
let horizontalx = x2 - x1;
let verticaly = y2 - y1;
linhaVertical(x1, y1, verticaly);
linhaHorizontal(x1, y1, horizontalx);
linhaVertical(x2, y2, verticaly);
linhaHorizontal(x2, y2, horizontalx);
}
function linhaVertical(x,y, size) {
for(let i=0; i < size; i++) {
acender(x, y + i);
}
}
function linhaHorizontal(x,y, size) {
for(let i=0; i < size; i++) {
acender(x + i, y);
}
}
function acender(x, y) {
let index = (x + y * width) * 4;
imageData.data[ index ] = 0;
imageData.data[ index + 1] = 0;
imageData.data [ index + 2] =0;
imageData.data[ index + 3 ] = 255;
}
Thank you for your attention in advance