JSFiddle - React, Tailwind, and code Playground

HTML

<canvas id="myCanvas" width="300" height="100"></canvas>

JavaScript

var c = document.getElementById("myCanvas");
var context =c.getContext("2d");

timer = window.setInterval(draw_line, 30);
function Point(x,y) {
    this.x = x;
    this.y = y;
}
Point.prototype.translateX = function(x) {
    return this.x += x;
};
Point.prototype.translateY = function(y) {
    return this.y += y;
};

var p1 = new Point(0,0);
var p2 = new Point(100,100);
var cp1 = new Point(15,45);
var cp2 = new Point(85,45);

function draw_line()
{
    context.fillStyle = "#000";
    context.fillRect(0, 0, c.width, c.height);

    context.beginPath();
    context.lineWidth = 2;
    context.strokeStyle = '#fff';

        //Where p1, p2, cp1, cp2 are point objects that has x & y values already defined    
    context.moveTo(p1.x, p1.y);
    context.bezierCurveTo(cp1.x,cp1.y,cp2.x,cp2.y,p2.x,p2.y);
    context.stroke();
    context.closePath();

    p1.translateX(1);
    p2.translateX(1);
    cp1.translateX(1);
    cp2.translateX(1);
    
    if (p1.x > 300) {
        p1.translateX(-400);
        p2.translateX(-400);
        cp1.translateX(-400);
        cp2.translateX(-400);        
    }
        // now i have to move p1, p2 ,cp1,cp2
        // now here is my problem
}