I'm building an arena using resources of HTML/JS
with canvas
.
I have the following code:
function montarArena() {
var canvas;
var heightCanvas = 498;
var widthCanvas = 598;
var qtdLinhas = $('#larguraCampo').val();
var qtdColunas = $('#alturaCampo').val();
var tamanhoLinha = widthCanvas / qtdLinhas;
var tamanhoColuna = heightCanvas / qtdColunas;
canvas = document.getElementById('imageView');
context = canvas.getContext('2d');
context.strokeStyle = '#000000';
context.fillStyle = '#fff';
context.clearRect(1, 1, widthCanvas, heightCanvas);
console.log("tamColuna: " + tamanhoColuna + " tamLinha: " + tamanhoLinha + " QtdColunas: " + qtdColunas + " QtdLinhas: " + qtdLinhas);
for (i = 0; i <= qtdLinhas; i++) {
for (j = 0; j <= qtdColunas; j++) {
context.strokeRect(j, i, tamanhoLinha * i, tamanhoColuna * j);
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><inputtype="range" id="larguraCampo" value="1" min="1" max="25" onchange="montarArena()" />
<input type="range" id="alturaCampo" value="1" min="1" max="25" onchange="montarArena()" />
<br/><br/><br/><br/><br/><br/>
<canvas id="imageView" width="600" height="500"></canvas>
As the number of lines is increased, the arena is getting crooked .... As follows:
Ineedittofit,justlikeatableitself:
I'm not realizing where I'm going wrong.