Files
coding-bench/tests/referenz/d-11/index.html

26 lines
2.1 KiB
HTML

<!doctype html>
<html lang="de"><head><meta charset="utf-8"><title>Sonnensystem</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#05060f;color:#ddd;font-family:sans-serif}
#space{position:relative;width:1280px;height:760px}
#sun{position:absolute;left:655px;top:405px;width:50px;height:50px;margin:-25px 0 0 -25px;border-radius:50%;background:#fc3;box-shadow:0 0 40px #fa0}
.planet{position:absolute;border-radius:50%;cursor:pointer;margin:-8px 0 0 -8px;width:16px;height:16px}
#info{position:absolute;left:10px;top:10px;width:300px}
#pause{position:absolute;right:10px;top:10px}
</style></head><body>
<div id="space"><div id="sun"></div><div id="info">Klicke auf einen Planeten</div><button id="pause">Pause</button></div>
<script>
const data=[["merkur","Merkur",50,"#aaa",4,"4879 km"],["venus","Venus",80,"#e9c",3.2,"12104 km"],["erde","Erde",115,"#4af",2.6,"12742 km"],["mars","Mars",150,"#e64",2.1,"6779 km"],["jupiter","Jupiter",200,"#d96",1.4,"139820 km"],["saturn","Saturn",250,"#eb8",1.1,"116460 km"],["uranus","Uranus",295,"#8dd",0.8,"50724 km"],["neptun","Neptun",335,"#46f",0.6,"49244 km"]];
const space=document.getElementById("space"),info=document.getElementById("info");
let paused=false;const els=[];
for(const [id,name,r,col,sp,dia] of data){
const o=document.createElement("div");o.style.cssText=`position:absolute;left:655px;top:405px;width:${2*r}px;height:${2*r}px;margin:${-r}px 0 0 ${-r}px;border:1px solid #223;border-radius:50%`;space.appendChild(o);
const p=document.createElement("div");p.className="planet";p.dataset.planet=id;p.style.background=col;
p.onclick=()=>{info.textContent=`${name}: Durchmesser ${dia}, Abstand ${r} Einheiten`};space.appendChild(p);els.push([p,r,sp,Math.random()*6]);
}
let last=performance.now();
function tick(t){const dt=(t-last)/1000;last=t;for(const e of els){if(!paused)e[3]+=dt*e[2]*0.6;e[0].style.left=(655+e[1]*Math.cos(e[3]))+"px";e[0].style.top=(405+e[1]*Math.sin(e[3]))+"px"}requestAnimationFrame(tick)}
requestAnimationFrame(tick);
document.getElementById("pause").onclick=()=>{paused=!paused};
</script></body></html>