1
如何在下面的代码中控制SVG?这是一个JS代码,应该围绕太阳SVG旋转地球SVG。我唯一的问题,我从来没有与SVG结合使用JS之前?一旦我知道如何旋转地球svg,我会弄清楚如何做其他行星,所以只要忽略其他行星。用JavaScript处理SVG?
我svgs:
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" viewBox="0 0 1000 600">
<style>
.st0{fill:#FFFF00;} .st1{fill:#808080;} .st2{fill:#EA9C4E;} .st3{fill:#3FA9F5;} .st4{fill:#F15A24;} .st5{fill:#DDC966;} .st6{fill:#A566C6;} .st7{fill:#3D9EC9;} .st8{fill:#2C709B;}
</style>
<circle id="Sun" cx="496.3" cy="300.4" r="45.2" class="st0"/>
<circle id="Mercury" cx="423.6" cy="300.8" r="5.8" class="st1"/>
<circle id="Venus" cx="576.8" cy="250.7" r="10.3" class="st2"/>
<circle id="Earth" cx="386.2" cy="357.4" r="11" class="st3"/>
<circle id="Mars" cx="628.8" cy="360.7" r="8.2" class="st4"/>
<circle id="Jupiter" cx="505.9" cy="509.8" r="19.6" class="st5"/>
<circle id="Saturn" cx="402.1" cy="156.8" r="14.2" class="st6"/>
<circle id="Uranus" cx="235.9" cy="265.9" r="7" class="st7"/>
<circle id="Neptune" cx="737.7" cy="310.1" r="9" class="st8"/>
</svg>
我的旋转JS代码:
<script>
function rotate_point(pointX, pointY, originX, originY, ang) {
ang = Math.PI/180.0;
return {
x: Math.cos(ang) * (pointX-originX) - Math.sin(ang) * (pointY-originY) + originX ,
y: Math.sin(ang) * (pointX-originX) + Math.cos(ang) * (pointY-originY) + originY
};
}
var Solarsystem = {
Earth:
{
render: function()
{
st0(386.2,357.4,10, 0, 2*Math.PI, true);
}
}
, Sun: {
render: function(){
gravitySun = rotate_point();
st0(496.3,300.4,10, 0, 2*Math.PI, true);
}
}
}
function animate()
{
}
var animateInterval = setInterval(animate, 1000/60);
}
</script>
排序关题目,是不是金星的轨道应该比地球快? – zer00ne
谢谢,这正是我需要的。而且,zer00ne,是的,金星比地球旋转的速度快1.6倍,提供的代码让我可以自己调整。我不认为他真的需要担心这种准确性。 – JohnMichael