Fixed an off-by-one error (two of them actually)

This commit is contained in:
Natty 2023-09-03 01:15:59 +02:00
parent 14e469c139
commit ab7cbc7390
No known key found for this signature in database
GPG key ID: BF6CB659ADEE60EC

View file

@ -23,13 +23,15 @@ function render(users, selfUser) {
const tasks = [];
totalImg += 1;
remainingImg += 1;
loadImage(ctx,
selfUser.avatar,
(width / 2) - 110,
(height / 2) - 110,
110,
"@" + selfUser.handle,
tasks);
tasks);
// loop over the layers
for (let layerIndex= 0; layerIndex < 3; layerIndex++) {
@ -37,9 +39,12 @@ tasks);
// loop over each circle of the layer
for (let i = 0; i < numb[layerIndex]; i++) {
remainingImg += 1;
// if we are trying to render a circle, but we ran out of users, just exit the loop. We are done.
if (userNum >= users.length) break;
totalImg += 1;
remainingImg += 1;
// We need an offset or the first circle will always on the same line, and it looks weird
// Try removing this to see what happens
const offset = layerIndex * 30;
@ -65,8 +70,6 @@ tasks);
}
}
totalImg = remainingImg;
ctx.font = "12px sans-serif";
ctx.fillStyle = "silver";
ctx.fillText("Be gay do crime uwu", 10, 15);
@ -129,6 +132,7 @@ function loadImage(ctx, url, x, y, r, name, tasks) {
};
img.onerror = function() {
console.error(`Error loading image: ${url}}`);
decrementRemaining();
};