我如何在javascript中做圆周运动

CGU*_*eno -3 javascript khan-academy

我正在尝试使用 javascript 制作太阳系,我正在使用可汗学院制作它,但我知道如何让它们围绕太阳绕圈移动我一直在网上浏览几个小时,但我不能找不到任何东西。这是我的项目,以便您可以看到我做了什么以及您可以在其中做什么

https://www.khanacademy.org/computer-programming/solar-system/6120244512161792

geo*_*org 7

只是为了让您开始:

x = 100  // center
y = 50   // center
r = 50   // radius
a = 0    // angle (from 0 to Math.PI * 2)

function rotate(a) {
  
  var px = x + r * Math.cos(a); // <-- that's the maths you need
  var py = y + r * Math.sin(a);
  
  document.querySelector('#point').style.left = px + "px";
  document.querySelector('#point').style.top = py + "px";  
}


setInterval(function() {
  a = (a + Math.PI / 360) % (Math.PI * 2);
  rotate(a);
}, 5);
Run Code Online (Sandbox Code Playgroud)
div {
  position: fixed;
  width: 10px;
  height: 10px;
}

#center {
  left: 100px;
  top: 50px;
  background: black;
}

#point {
  left: 0px;
  top: 0px;
  background: red;
}
Run Code Online (Sandbox Code Playgroud)
<div id="center"></div>
<div id="point"></div>
Run Code Online (Sandbox Code Playgroud)