Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
How to fix the graphing line on math calculator with initial scale [Resolved]

Im currently building an math graphing calculator in discord.js, the graphing work fine on 1.0x scale but when im changing the scale the graphing line start not right with the axes, I saw it to be move to bottom-left not to be the center of the graph

function draw(tree) {
    var i = 0;
    dx = 1 / global_scale;

    var y;
    variables.x = minX;

    var width = canvas.width;

    while (isNaN((y = eval(tree))) && i < width) {
        variables.x = minX + i * dx;
        i++;
    }

    let previousY = (y - minY) * global_scale;

    for (; i < width; i++) {
        variables.x = minX + i * dx;
        y = eval(tree);

        if (isNaN(y)) {
            console.log(`discontinuity at x = ${x}`);
            while ((y = eval(tree)) === NaN && i < width) {
                variables.x = minX + i * dx;
                i++;
            }
            previousY = (y - minY) * global_scale;
            continue;
        }

        y = (y - minY) * global_scale;

        ctx.beginPath();
        ctx.moveTo(i - 1, previousY);
        ctx.lineTo(i, y);
        ctx.lineWidth = 2;
        ctx.stroke();
        previousY = y;
    }
}```

[The graphing when i do x^2 with 0.01 initial scale][1]

[The graphing when i do sin(x) with 0.01 initial scale][2]


and i wanna it to be something like this :
[The graphing when i do x^2 with 1.0 initial scale][3]


  [1]: https://i.stack.imgur.com/WTTl6.png
  [2]: https://i.stack.imgur.com/8fH4n.png
  [3]: https://i.stack.imgur.com/hefWl.png
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda