summaryrefslogtreecommitdiff
path: root/projects/projectile/index.js
blob: 4226da59c1e5483b3057abd216df2a851f33eb15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40


let projectile= function (node){

    node.setup = function() {
        node.createCanvas(width, height);
    };


    let t=0;
    let v0=50
    let x0=1
    let y0=50
    let g=9.81
    let width=800
    let height=200
    let dots=[]
    function x(t) {
        return x0+v0*t
    }

    function y(t) {
        return height - (-1/2 * g * t**2 + v0 * t + y0)
    }

    node.draw = function() {
        node.background(50);
        dots.forEach((elt)=>{node.ellipse(elt[0],elt[1],4,4);})
        node.ellipse(x(t),y(t),20,20);
        dots.push([x(t),y(t)])
        if(t>10){
            node.noLoop()
        }
        t+=0.07
    };

    node.a=function(){
        node.remove()
    }
};