JSFiddle - React, Tailwind, and code Playground

HTML

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

<head>
  <title>Elastic collisions</title>
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'/>">

  <style>
    body { font-size: 12px; }
    table { width: min-content; }
    table td { vertical-align: top; padding: 0.33em; }
    input { margin-bottom: 0.8em; }
    #canvas { border: 1px solid #000; }
  </style>
</head>

<body>
  <table>
    <tr>
      <td>
        <label for="atomSize">Atom size</label>
        <input type="text" id="atomSize" />

        <label for="numberOfAtoms">Number of atoms</label>
        <input type="text" id="numberOfAtoms" />

        <label for="startVelocity" title="module, direction">Start velocity</label>
        <input type="text" id="startVelocity" />

        <label for="gravity">Gravity</label>
        <input type="text" id="gravity" />

        <label for="picoSecondsPerSecond" title="Big time factor can cause incorrect collision processing">Time factor</label>
        <input type="text" id="picoSecondsPerSecond" />

        <label for="atomMassFrom" title="from, to">Atom mass</label>
        <input type="text" id="atomMassFrom" />

        <button id="startButton" data-switch-title="Stop">Start</button>
        <button id="saveState" style="float: right">Save state</button>
      </td>
      <td>
        <canvas id="canvas" width="800" height="240"></canvas>
      </td>
    </tr>
  </table>

  <script>

    (function () {
      const $ = (selector, parent) => (parent ?? document).querySelector(selector)

      // units, just for clarity
      const PM = 1
      const PM_PER_PSEC = 1
      const KG = 1
      const RADIAN = 1

      const ONE_ATOM_MASS = 1.66e-27*KG

      // for simplicity and performance we assume that all atoms have the same radius
      const ATOM_DIAMETER = 300*PM


      const settings = {
        atomSize: 6,
        numberOfAtoms: 1800,
        startVelocity:...