How to bring the Point at to the right place into the canvas?
let canvas = []
let canvasHeight = process.stdout.getWindowSize()[1] -25
let canvasWidth = process.stdout.getWindowSize()[0]
function createCanvas (){
for(i = 0; canvasHeight > i; i++){
const row = []
for(j = 0; canvasWidth > j; j++){
row.push(" ")
}
canvas.push(row)
}
}
createCanvas()
function createAPointIntoTheCanvas (x,y) {
if(x>= 0 &&x < canvasWidth && y >= 0 && y < canvasHeight){
canvas[x][y] = "+"
}
}
createAPointIntoTheCanvas(5,5)
console.log(canvas.join(" "))
The problem is that the point is written to the canvas but into the wrong place. Written with NodeJs
PS: Please copy the sourcecode into a js file. Afterwards start the file with node nameOfYourFile.js.