d-11 mit Nutzertext (Canvas, Zeichenabfang und künstliche Uhr), Image-Label cb.hash mit Veraltet-Prüfung, lokaler Webserver und Im Browser öffnen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
39
tests/referenz/d-11-varianten/statisch.html
Normal file
39
tests/referenz/d-11-varianten/statisch.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!doctype html><html lang="de"><head><meta charset="utf-8"><title>Sonnensystem</title>
|
||||
<style>
|
||||
html,body{margin:0;background:#04050d;color:#dde;font-family:sans-serif}
|
||||
#bar{display:flex;gap:12px;align-items:center;padding:8px 12px}
|
||||
canvas{display:block}
|
||||
</style></head><body>
|
||||
<div id="bar"><button id="toggle">Pause</button><label>Geschwindigkeit <input id="speed" type="range" min="1" max="100" value="10"></label><button id="reset">Zurücksetzen</button><span id="time">Simulationszeit: 0.00 Jahre</span></div>
|
||||
<canvas id="c" width="1280" height="740"></canvas>
|
||||
<script>
|
||||
// Simulationslogik: Zeit in Tagen, Positionen aus der vergangenen Simulationszeit.
|
||||
const PLANETS=[["Merkur",87.97,"#aaa",3],["Venus",224.7,"#e8c",5],["Erde",365.26,"#4af",5.5],["Mars",686.98,"#e64",4],["Jupiter",4332.6,"#d96",11],["Saturn",10759,"#eb8",9.5],["Uranus",30688,"#8dd",7.5],["Neptun",60182,"#46f",7]];
|
||||
const sim={days:0,running:true,speed:10}; // speed: Erdjahre pro Sekunde / 10
|
||||
const angleOf=p=>2*Math.PI*sim.days/p[1];
|
||||
// Darstellung
|
||||
const cv=document.getElementById("c"),ctx=cv.getContext("2d"),cx=640,cy=370;
|
||||
const stars=document.createElement("canvas");stars.width=cv.width;stars.height=cv.height;const sx=stars.getContext("2d");
|
||||
sx.fillStyle="#04050d";sx.fillRect(0,0,stars.width,stars.height);
|
||||
let seed=7;const rnd=()=>(seed=(seed*16807)%2147483647)/2147483647;
|
||||
for(let i=0;i<220;i++){sx.fillStyle=`rgba(255,255,255,${0.4+rnd()*0.6})`;sx.fillRect(rnd()*stars.width,rnd()*stars.height,1+rnd()*1.5,1+rnd()*1.5)}
|
||||
const radius=i=>45+i*43;
|
||||
function draw(){
|
||||
ctx.drawImage(stars,0,0);
|
||||
ctx.strokeStyle="#334";ctx.lineWidth=1;
|
||||
PLANETS.forEach((p,i)=>{ctx.beginPath();ctx.arc(cx,cy,radius(i),0,2*Math.PI);ctx.stroke()});
|
||||
ctx.beginPath();ctx.arc(cx,cy,20,0,2*Math.PI);ctx.fillStyle="#fc3";ctx.fill();
|
||||
ctx.fillStyle="#fc8";ctx.font="12px sans-serif";ctx.fillText("Sonne",cx-16,cy+34);
|
||||
PLANETS.forEach((p,i)=>{const a=angleOf(p),x=cx+radius(i)*Math.cos(a),y=cy+radius(i)*Math.sin(a);
|
||||
ctx.beginPath();ctx.arc(x,y,p[3],0,2*Math.PI);ctx.fillStyle=p[2];ctx.fill();
|
||||
ctx.fillStyle="#ccd";ctx.fillText(p[0],x+p[3]+3,y-p[3])});
|
||||
document.getElementById("time").textContent=`Simulationszeit: ${(sim.days/365.26).toFixed(2)} Jahre`;
|
||||
}
|
||||
// Interaktion
|
||||
let last=null;
|
||||
function frame_unused(t){if(last!==null&&sim.running){const dt=(t-last)/1000;sim.days+=dt*sim.speed*365.26/10}last=t;draw();requestAnimationFrame(frame)}
|
||||
document.getElementById("toggle").onclick=e=>{sim.running=!sim.running;e.target.textContent=sim.running?"Pause":"Start"};
|
||||
document.getElementById("speed").oninput=e=>{sim.speed=Number(e.target.value)};
|
||||
document.getElementById("reset").onclick=()=>{sim.days=0;draw()};
|
||||
draw();
|
||||
</script></body></html>
|
||||
Reference in New Issue
Block a user