Answer the question
In order to leave comments, you need to log in
How to solve the problem when drawing on canvas with pixel coordinates, when fractional values are obtained?
Greetings!
Simplified description:
I'm doing something like a calendar grid,
I'm drawing a rectangle 400 pixels wide - the month of February
has 29 days and you need them to be equal in width, i.e.
400/29 = 13.79
draw
29 vertical lines
values can only be integers,
after the last column there is a lot of empty space, although it should not be =(
In the figure, all lines are 1 pixel wide.
Can you please tell me how to solve this problem more elegantly?
Answer the question
In order to leave comments, you need to log in
...
var w = 400 / 29; // или 28
var x1, x2;
for(var i=0;i<29;i++) {
x1 = Math.floor(i * w);
x2 = Math.floor(x1 + w);
// И тут рисуете прямоугольник от (x1, y1) до (x2, y2), где y1 - где заканчивается "февраль", а y2 - конец экрана.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question