Answer the question
In order to leave comments, you need to log in
How to arrange elements randomly in canvas, taking into account the borders of the canvas?
How to arrange elements randomly in canvas, taking into account the borders of the canvas (so that the elements do not go beyond), considering the center of the canvas, let's say the size is 100px X 100px, so that the elements do not fall into the center either.
PS Randomly rendered elements. Confusion with the definition of the center and boundaries.
Answer the question
In order to leave comments, you need to log in
if(x>0 && x<canvas.width - el.width && Math.abs(canvas.width/2 - x) > el.width/2) {
// рисуем элемент
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question