English 中文(简体)
• 如何将正确位置印入 can? Madeed with NodeJS
原标题:How to print point into the right position into the canvas? Made with NodeJS

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.

问题回答

问题必须是:

let canvasHeight  = process.stdout.getWindowSize()[1] -25

It results in a height of 0 if the window is small. If I set the width and height manually your code works.

let canvas = []
let canvasHeight  = 5  //process.stdout.getWindowSize()[1] -25
let canvasWidth = 5    //process.stdout.getWindowSize()[0]

//...

createCanvas()
createAPointIntoTheCanvas(2,2)
console.log(canvas)

结果:<代码>+> 载于2,2

[
  [    ,    ,    ,    ,     ],
  [    ,    ,    ,    ,     ],
  [    ,    ,  + ,    ,     ],
  [    ,    ,    ,    ,     ],
  [    ,    ,    ,    ,     ]
]




相关问题
ZOrder with Canvas within the List

我有一份清单,其中载有一些控制措施,包括一名扩大成员。 在扩大小组内还有另一个名单,我想把这份清单放在外。 这里简单地重提:

Detecting drawn shapes in Canvas+Javascript?

I had an idea for a WebOS, but it requires detecting drawn shapes. Ie: I want a user to be able to draw an image, then draw a big box around the whole image. Then the user can drag that box by the ...

Canvas Element and IE

Well not just IE, any browser that doesn t currently support it I want to start using the processing.js framework. It s used for making images with the canvas element. However I m reluctant to use it ...

Bezier timed animation path

I m trying to define a path of points. Each point has an x, y, and time. I then want to query this path and get the current position at that point in time. Let me share some pseudo code. point {x, ...

Rendering web page as thumbnail

I asked this question earlier, since I am a little new to Firefox extension development, the canvas thing for Firefox went a little over my head. Apologies for reposting this again. with the first ...

热门标签