JSFiddle - React, Tailwind, and code Playground

by twobomb three

HTML

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>

    <div class="container">
        <div class="crash">
            <canvas id="crashCanvas" width="500" height="300"></canvas>
        </div>
    </div>

    <script src="main.js"></script>

</body>

</html>

CSS

* {
    box-sizing: border-box;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

.crash {
    display: flex;
    justify-content: center;
    margin-top: 50px;
}

#crashCanvas {
    border: 1px solid black;
}

JavaScript

const canvas = document.getElementById('crashCanvas')
const ctx = canvas.getContext('2d')
var endNumber = 10;//Конечное число
var animationDuration = 5000;//Длительность анимации в милисекундах

function crashTimer() {
    let crashTimerCount = 3
    let crashTimerCounter = setInterval(crashTimerInner, 1000);
    function crashTimerInner() {
        if (crashTimerCount < 1) {
            clearInterval(crashTimerCounter)
            crashStart(Date.now());
            return crashTimerCount
        }
        crashTimerCount = crashTimerCount - 1
        ctx.fillStyle = "black"
        ctx.font = "36px serif"
        ctx.clearRect(0, 0, 500, 300)
        ctx.fillText(`Place your bets... ${crashTimerCount}`, canvas.width / 5, canvas.height / 2)
	
    }
}
function crashStart(timeStart) {
    		ctx.clearRect(0, 0, 500, 300)
        ctx.lineWidth = 2
        ctx.beginPath();
        ctx.moveTo(arrDots[0][0], arrDots[0][1]);
        var timePassed = Date.now() -  timeStart;
        var p = timePassed > animationDuration?1:timePassed/animationDuration;
        var inx = Math.round(arrDots.length * p);
        for (let i = 1; i < inx; i++) 
            ctx.lineTo(arrDots[i][0], arrDots[i][1])
        ctx.stroke();
        
    		ctx.fillText(`${(inx/arrDots.length * endNumber).toFixed(2)}x`, canvas.width / 2.3, canvas.height / 1.9);
    if (p < 1) 
        setTimeout(() => { crashStart(timeStart) }, 1000 / 60)

}


var arrDots =...