/*
title: Galactic Navigator โ Curved Flight Plan
categories: geometry, astronomy, vector, navigation
files:
../point_src/core/head.js
../point_src/pointpen.js
../point_src/pointdraw.js
../point_src/point-content.js
../point_src/pointlist.js
../point_src/point.js
../point_src/stage.js
../point_src/events.js
../point_src/automouse.js
../point_src/distances.js
../point_src/functions/clamp.js
../point_src/dragging.js
*/
class MainStage extends Stage {
canvas='playspace';
mounted(){this.t=0;this.zoom=1;this.panX=0;this.panY=0;this.keys={};window.addEventListener('keydown',e=>{this.keys[e.code]=true;if(e.code.startsWith('Arrow')||e.code==='Equal'||e.code==='Minus')e.preventDefault()});window.addEventListener('keyup',e=>{this.keys[e.code]=false});}
draw(ctx){
const w=this.canvas.width,h=this.canvas.height,t=this.t++/60;
this.panX+=((this.keys.ArrowLeft?1:0)-(this.keys.ArrowRight?1:0))*2.5;
this.panY+=((this.keys.ArrowUp?1:0)-(this.keys.ArrowDown?1:0))*2.5;
if(this.keys.Equal||this.keys.NumpadAdd)this.zoom=Math.min(3,this.zoom*1.012);
if(this.keys.Minus||this.keys.NumpadSubtract)this.zoom=Math.max(.55,this.zoom/1.012);
ctx.fillStyle='#080d14';ctx.fillRect(0,0,w,h);
const k=Math.min(w/950,h/640)*this.zoom;
ctx.save();ctx.translate(w/2+this.panX,h/2+this.panY);ctx.scale(k,k);
const nodes=[
[-340,100,0,'RIGEL','#84a5b6',11],
[-195,-75,45,'ORION WAYPOINT','#b4a69b',15],
[-20,115,-35,'SOL','#d5bd8a',12],
[146,-70,78,'OUTER BEACON','#91b2aa',18],
[310,48,-42,'LOCAL SECTOR','#b4a0b9',25]
];
const project=p=>[p[0]+p[2]*.36,p[1]-p[2]*.2];
for(let i=0;i<160;i++){
let x=((i*127.73)%947)-475,y=((i*283.19)%641)-320;
ctx.fillStyle='#6d8993';ctx.globalAlpha=.16+(i%5)*.04;
ctx.fillRect(x,y,1,1);
}ctx.globalAlpha=1;
ctx.strokeStyle='#1b303c';ctx.lineWidth=.8;
for(let i=-4;i<=4;i++){ctx.beginPath();ctx.moveTo(-440,i*65);ctx.lineTo(440,i*65);ctx.stroke();}
// Projected systems, faint orbit rings and local reference grids.
for(let i=0;ibez(route[ix][axis],route[ix+1][axis],route[ix+2][axis],route[ix+3][axis],u));
ctx.fillStyle='#f0eac2';ctx.beginPath();ctx.arc(pos[0],pos[1],4,0,Math.PI*2);ctx.fill();
ctx.restore();
ctx.textAlign='left';ctx.font='14px monospace';ctx.fillStyle='#b8d5cd';ctx.fillText('NAVIGATION / CURVED TRANSIT PLAN',22,32);
ctx.font='11px monospace';ctx.fillStyle='#849c9c';ctx.fillText('LOCAL STELLAR SPACE ยท SCHEMATIC / NOT TO SCALE',22,53);
ctx.fillText('ARROWS: PAN +/-: ZOOM',22,h-20);
ctx.textAlign='right';ctx.fillStyle='#a9c6ae';ctx.fillText('ROUTE CLEARANCE: NOMINAL',w-22,h-20);
}
}
stage=MainStage.go();