( i'm not english but i'll try my best to explain )
i have some issues to rotate a matrix after a click on a button i tried this How to rotate a matrix in an array in javascript but i failed to adapt it to my code .
so here is my html button :
<script type="text/javascript" src="genmap.js"></script>
<button onclick="rotate()">Tourner -></button>
<div style="display:auto;">
<canvas id="main" height="2000" width="5000"></canvas>
</div>
and my matrix ( square ) is randomly generated and look like this :
var map = [];
for(var i=0; i < size; i++) {
map[i] = new Array(size);
}
for(var j = 0; j < size; j++){
for ( var i = 0; i < size ; i++){
map[j][i] = Math.floor ( Math.random() * 2 );
}
}
i use a tuto for canvas , and my script begin with
(function main(isometric) {
and end with
})(this);
i don't know if i should put my function rotate in or out ...
neither how to trigger it with a click on " tourner -> "
i think i need to duplicate ( and rename ) my script but with map2 instead of map and change the random generation with the rotation from map , but i don't even know if it's possible :/
i tried this
for(var j = 0; j < size; j++){
for ( var i = 0; i < size ; i++){
maproteun[i][j] = map[size-i][j];
}
}
after the map generation but for some reason , it stop the creation of the first matrix and don't even draw the map
can you please help me ?
EDIT : things are moving i'm able to clear the canvas , but i'm unable to reload the function ( or it doesn't work ) to redraw one i use clearRect to clear it , but if i write
main();
it don't redo the function