I have recently been learning how to use two.js and I want to make a circle orbit around another object like a planet. Since it needs to pass behind the object its orbiting around, I'm trying to dynamically change the circle's size as it moves to create the illusion of depth. I saw another overflow question about changing size in two.js using a matrix and tried to apply it here but I cannot get the size changes to match sync with the orbital motion. I would appreciate any help.
JS bin (since it needs two.js library this doesn't produce anything at first but I made it for the convenience of anyone who wants to help): https://jsbin.com/rugakojivu/edit?html,output
<html>
<head>
<script src = "two.js"></script>
</head>
<body>
<div id = "frame"></div>
<script>
var el = document.getElementById("frame");
var two = new Two({fullscreen:true}).appendTo(el);
var bigAngle = 0,
smallAngle = 0,
distance = 10,
radius = 50,
orbit = 200,
orbits = two.makeGroup();
var offset = 300;
function getPositions(angle, orbit) {
return {
x: Math.cos(angle * Math.PI / 180) * orbit,
y: Math.sin(angle * Math.PI / 180) * orbit
};
}
var pos = getPositions(bigAngle,orbit),
big = two.makeCircle(pos.x+offset,pos.y+offset,radius);
big.stroke="#123456";
big.linewidth=7;
big.fill="#194878";
big._matrix.manual=true;
two.bind("update",function(frameCount){
var pos = getPositions(bigAngle++,orbit);
big.translation.x=pos.x+offset;
big.translation.y=pos.y+offset;
});
two.bind("update",function(frameCount,timeDelta){
var sx=Math.sin(frameCount/200);
big._matrix
.identity()
.translate(big.translation.x, big.translation.y)
.rotate(big.rotation)
.scale(sx);
});
two.play();
</script>
</body>
</html>