Animated Functions

Not just plot, but also animate the functions added variable t.

Code

            
    elem=document.querySelector(".example-container");
    setCanvas(elem);
    
    t=0;
    function draw(){
        clearCanvas();
        points=[];
        new line(WIDTH/2,0,WIDTH/2,HEIGHT,'#fff',0.5);
        new line(0,HEIGHT/2,WIDTH,HEIGHT/2,'#fff',0.5);

        for(i=0;i<WIDTH;i++){
            x=mapRange(i,0,WIDTH,-10,10);
            y=eval(document.getElementById("inpfunc").value);
            points.push([i,HEIGHT/2-y]);
        }

        new polygon(points,'#695fe6',0,'#695fe6',2,false);
        t+=0.01;
            
        requestAnimationFrame(draw);
    }
    
    draw();

    // use draw() as onchange event for input box.