以下のコードは、線で接続できるグラフ (キャンバス) 上の 2 つのランダムな点を生成します。
<script>
function random() {
var point1X = (Math.floor(Math.random() * 10) + 1);
var point1Y = (Math.floor(Math.random() * 2) - 10); // first two lines generate first coordinate on graph
var point2X = (Math.floor(Math.random() * 100) + 10);
var point2Y = (Math.floor(Math.random() * 2) - 10); // second two lines generate second point
document.getElementById("empty").innerHTML += "(" + point1X + ", " + point1Y + ") (" + point2X + ", " + point2Y + ")<br />"; // here coordinates are displayed on the page.
}
</script>
すべてを線で接続する必要があるため、生成された 2 番目の座標を 3 番目の座標と同等にする必要があります (ただし、生成される 4 番目の座標は異なる必要があります)。
これを説明するのは非常に難しいので、この図が役立つことを願っています: http://i6.minus.com/jKIhdChUNWZt7.png .
誰かがこれを明確に説明できる場合は、これを編集します。