ここで引用されている例を利用しようとしています: http://www.physicsforums.com/showthread.php?t=248191
この例を利用する単純な JavaScript を作成しました (または、少なくとも意図したとおりです) が、角度として設定したものに反応する方法に完全に当惑しています。私はそれがどこで動作することを期待しています (極座標を使用すると仮定します)、角度として 0 を使用すると、スポットは円の東側、南側で 90 度、西側で 180 になるはずです。ただし、これはまったく機能していません。それが何をしているのかを説明することすらできません。0~4.7くらいの間をぐるぐる回っているようです。もちろん、私がこれを完全に台無しにして、本当に明白な何かを見逃している可能性があります (おそらく)。
とにかく...私のコードは完全に下にあります。実行するには、新しい .html ドキュメントにカット アンド ペーストするだけです。私は何が間違っているのか本当に興味があります。
<HTML>
<script>
startMotion = function(){
setInterval("moveDots()", 1000);
}
function moveDots(){
oDot = document.getElementById("oDot");
iDot = document.getElementById("iDot");
tDisplay = document.getElementById("tDisplay");
oDot.style.left = (t1Radius*(Math.cos(angle)) + ccX)+ "px"
oDot.style.top = (t1Radius*(Math.sin(angle)) + ccY)+ "px"
iDot.style.left = (t2Radius*(Math.cos(angle)) + ccX) + "px"
iDot.style.top = (t2Radius*(Math.sin(angle)) + ccY)+ "px"
tDisplay.value = "x=" + iDot.style.left + "\n";
tDisplay.value += "y=" + iDot.style.top + "\n";
tDisplay.value += "angle=" + angle + "\n";
angle += angleSpeed;
angle %= 360;
}
var angleSpeed = 5; //amount of change in angle from animation point to animation point
var ccX = 200; //circle center coordinate X
var ccY = 200; //circle center coordinate Y
var t1Radius = 200; //radius for outside dot
var t2Radius = 100; //radius for inside dot
var angle = 0; //this number will keep changing to move the dots around the circumference
</script>
<style>
body{
text-align:center;
margin:0;
}
#track{
margin: 0 auto;
text-align: left;
position: relative;
width:400px;
height:400px;
background-color:pink;
}
#iDot{
position:absolute;
top:0px;
left:0px;
width:10px;
height:10px;
background-color:green;
}
#oDot{
position:absolute;
top:0px;
left:0px;
width:10px;
height:10px;
background-color:blue;
}
#feedback{
position:absolute;
left:0px;
top:0px;
width:200px;
height:100px;
background-color:black;
}
#tDisplay{
background-color:black;
color:white;
font-size:10px;
font-family:arial, helvetica;
width:300px;
height:100px;
}
#center{
position:absolute;
left:195px;
top:195px;
width:10px;
height:10px;
background-color:white;
}
</style>
<body onLoad="startMotion()">
<div id="feedback">
<textarea id="tDisplay"></textarea>
</div>
<div id="track">
<div id="center"></div>
<div id="iDot"></div>
<div id="oDot"></div>
</div>
</body>
</html>