There are 2 loops in which each one has different results, and with those loops, the axes (x, y) of the canvas boxes are specified. But at the time of entering the parameters, I am not clear about how to organize the loops with the canvas path, or a way in which it is executed properly according to the for.
bucle de eje x = for (var i = 9; i <= 19; i++) {
x = 50*i;
}
bucle de eje y = for (var i = 10; i >= 1; i--) {
y = 50*i;
}
function funcDelRect(){
// for eje x
for (var i = 9; i <= 19; i++) {
x = 50*i;
console.log("1: " + x);
console.log('--------------------');
// for eje y
for (var i = 10; i >= 0; i--) {
y = 50*i;
console.log("2: " + y);
// Canvas Rect();
var canvas = document.getElementById('canvasGEO');
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.rect(x, y, 25, 25);
ctx.fillStyle = "gold";
ctx.fill();
ctx.stroke();
ctx.closePath();
}
}
}
<canvas style="background-color: lightgreen; border: 1px solid black" id="canvasGEO" width="1000" height="700"></canvas>
<button type="submit" id="agreeRect" onclick="funcDelRect()">Subir cuadros</button>