khan academy - How can i make a circular motion in javascript -
i'm trying make solar system using javascript, , i'm using khan academy make it, font know how can make them move in circle around sun kept browsing net hours, couldn't find anything. here's project can see have done , can in it
https://www.khanacademy.org/computer-programming/solar-system/6120244512161792
just started:
x = 100 // center y = 50 // center r = 50 // radius = 0 // angle (from 0 math.pi * 2) function rotate(a) { var px = x + r * math.cos(a); // <-- that's maths 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 + math.pi / 360) % (math.pi * 2); rotate(a); }, 5);
div { position: fixed; width: 10px; height: 10px; } #center { left: 100px; top: 50px; background: black; } #point { left: 0px; top: 0px; background: red; }
<div id="center"></div> <div id="point"></div>
Comments
Post a Comment