2D Equations

Very basic 2D equations plotter made using ChelseaJS.
Simple maths, nothing special.
Just Input the function of x you want to plot. The range of x is -10 to 10.

Code

            
    elem=document.querySelector(".example-container");
    setCanvas(elem);
    
    
    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);
        
            
        requestAnimationFrame(draw);
    }

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