I wrote this js canvas code. It works but it paints half of a canvas angularly. Can I do something to correct this code or I need to fully rewrite it. Is it right to put this code inside setup(). Thank you. https://p5js.org/reference/#/p5/random
var side = 10;
var grassArr = [];
var matrix = [];
console.log(matrix)
function setup() {
for(var y = 0; y<49; y++){
matrix[y] = [];
for(var x = 0; x<49; x++){
let arr = [0,1,2]
let r = random(arr)
matrix[x][y] = r
matrix.push(r)
}
}
frameRate(5)
createCanvas(49 * side, 49* side);
background('#acacac');
}
function draw(){
for (var y = 0; y < 49; y++) {
for (var x = 0; x < 49; x++) {
if(matrix[y][x]== 0){
fill('#acacac')
rect(x * side, y * side, side, side);
}
if(matrix[y][x]== 1){
fill('green')
rect(x * side, y * side, side, side);
}
if(matrix[y][x]== 2){
fill('yellow');
rect(x * side, y * side, side, side);
}
}
}
}