const GRAVITY = 9.81;
const PI = Math.PI

function szamol(event){
    event.preventDefault();
    var v0 = Number(document.getElementById("v0").value);
    var a = Number(document.getElementById("a").value);

    var rows = [];
    var prev = Array.from(document.getElementsByClassName("results"))
    for(i in prev){
        prev[i].remove();
    }

    var time = 0.000;
    do{
        x = calcx(v0, time, a);
        y = calcy(v0, time, a);
        var row = document.createElement("tr");
        row.classList = "results";
        var cel1 = document.createElement("td")
        cel1.textContent = time;
        row.appendChild(cel1)

        var cel2 = document.createElement("td")
        cel2.textContent = x;
        row.appendChild(cel2)

        var cel3 = document.createElement("td")
        cel3.textContent = y;
        row.appendChild(cel3)

        document.getElementById("outputtable").appendChild(row);
        console.log(row)

        time = Math.round(time*1000+100)/1000
    }while(calcy(v0, time, a) > 0)
}

function calcx(v0, t, a){
    a = a*(PI/180)
    var x =  v0 * t * Math.cos(a);
    x = Math.round(x*1000)/1000
    return x;
}

function calcy(v0, t, a){
    a = a*(PI/180)
    var y =  v0 * t * Math.sin(a) - (GRAVITY/2 * Math.pow(t, 2));
    y = Math.round(y*1000)/1000
    return y;
}