Fix galaxy flow motion and lock overlap separation
This commit is contained in:
@@ -24,17 +24,17 @@ export function layoutLockLabels(
|
||||
names: string[],
|
||||
starR: number,
|
||||
): LabelPlacement[] {
|
||||
const vaultPad = 52;
|
||||
const vaultPad = 108;
|
||||
const labels: LabelPlacement[] = starPositions.map((p, i) => {
|
||||
const ang = Math.atan2(p.y, p.x);
|
||||
const base = starR + 20;
|
||||
const base = starR + 28;
|
||||
return {
|
||||
x: p.x + Math.cos(ang) * base,
|
||||
y: p.y + Math.sin(ang) * base,
|
||||
};
|
||||
});
|
||||
|
||||
for (let iter = 0; iter < 28; iter++) {
|
||||
for (let iter = 0; iter < 48; iter++) {
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
const p = starPositions[i];
|
||||
const r = dist(labels[i], { x: 0, y: 0 });
|
||||
@@ -65,7 +65,7 @@ export function layoutLockLabels(
|
||||
labels[i].y - starPositions[i].y,
|
||||
labels[i].x - starPositions[i].x,
|
||||
);
|
||||
const minDist = starR + 16;
|
||||
const minDist = starR + 26;
|
||||
const dStar = dist(labels[i], starPositions[i]);
|
||||
if (dStar < minDist) {
|
||||
labels[i].x = starPositions[i].x + Math.cos(outward) * minDist;
|
||||
|
||||
@@ -33,7 +33,7 @@ export function flowOrbitPhysics(index: number, total: number): OrbitPhysics {
|
||||
rx: Math.min(rx, VIEW_R),
|
||||
ry: Math.min(ry, VIEW_R * 0.88),
|
||||
tiltDeg,
|
||||
speed: 0.05 + (index % 9) * 0.009 + band * 0.004,
|
||||
speed: 0.14 + (index % 9) * 0.018 + band * 0.008,
|
||||
phase: (index / n) * Math.PI * 2 + index * GOLDEN * 0.15,
|
||||
};
|
||||
}
|
||||
@@ -70,17 +70,19 @@ function dist(a: Vec2, b: Vec2): number {
|
||||
return Math.hypot(dx, dy);
|
||||
}
|
||||
|
||||
const layoutCache = new Map<number, Vec2[]>();
|
||||
const LAYOUT_VER = 2;
|
||||
const layoutCache = new Map<string, Vec2[]>();
|
||||
|
||||
/** Golden-angle seeds relaxed for minimum star separation (lock mode). */
|
||||
export function lockedPositions(total: number): Vec2[] {
|
||||
const cached = layoutCache.get(total);
|
||||
const key = `${LAYOUT_VER}:${total}`;
|
||||
const cached = layoutCache.get(key);
|
||||
if (cached) return cached;
|
||||
|
||||
const pts = Array.from({ length: total }, (_, i) => slotSeed(i, total));
|
||||
const minSep = total > 14 ? 38 : 44;
|
||||
const minSep = total > 12 ? 56 : 62;
|
||||
|
||||
for (let iter = 0; iter < 32; iter++) {
|
||||
for (let iter = 0; iter < 56; iter++) {
|
||||
for (let i = 0; i < total; i++) {
|
||||
for (let j = i + 1; j < total; j++) {
|
||||
const d = dist(pts[i], pts[j]);
|
||||
@@ -95,7 +97,7 @@ export function lockedPositions(total: number): Vec2[] {
|
||||
}
|
||||
}
|
||||
const r = dist(pts[i], { x: 0, y: 0 });
|
||||
const vaultPad = 78;
|
||||
const vaultPad = 96;
|
||||
if (r < vaultPad && r > 0.001) {
|
||||
const s = vaultPad / r;
|
||||
pts[i].x *= s;
|
||||
@@ -110,7 +112,7 @@ export function lockedPositions(total: number): Vec2[] {
|
||||
}
|
||||
}
|
||||
|
||||
layoutCache.set(total, pts);
|
||||
layoutCache.set(key, pts);
|
||||
return pts;
|
||||
}
|
||||
|
||||
@@ -127,10 +129,19 @@ export function moonPositions(
|
||||
baseSpread = 32,
|
||||
): { x: number; y: number; angle: number }[] {
|
||||
const out: { x: number; y: number; angle: number }[] = [];
|
||||
const outward = Math.atan2(cy, cx);
|
||||
for (let mi = 0; mi < count; mi++) {
|
||||
const slice = (mi / Math.max(count, 1)) * Math.PI * 2;
|
||||
const angle = flowing ? slice + time * (0.4 + mi * 0.06) : slice - Math.PI / 2;
|
||||
const dist = flowing ? baseSpread * 0.62 : baseSpread + (mi % 2) * 5;
|
||||
const fan =
|
||||
count <= 1
|
||||
? 0
|
||||
: (mi - (count - 1) / 2) * (flowing ? 0.55 : 0.42);
|
||||
const angle = flowing
|
||||
? slice + time * (0.85 + mi * 0.08)
|
||||
: outward + fan;
|
||||
const dist = flowing
|
||||
? baseSpread * (0.72 + (mi % 3) * 0.08)
|
||||
: baseSpread + 8 + mi * 6;
|
||||
out.push({
|
||||
angle,
|
||||
x: cx + Math.cos(angle) * dist,
|
||||
@@ -140,6 +151,52 @@ export function moonPositions(
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Push overlapping moons apart in lock mode (all stars). */
|
||||
export function relaxLockedMoons(
|
||||
stars: Vec2[],
|
||||
moonsByStar: Vec2[][],
|
||||
): Vec2[][] {
|
||||
const flat: { p: Vec2; star: number; moon: number }[] = [];
|
||||
for (let si = 0; si < moonsByStar.length; si++) {
|
||||
for (let mi = 0; mi < moonsByStar[si].length; mi++) {
|
||||
flat.push({ p: { ...moonsByStar[si][mi] }, star: si, moon: mi });
|
||||
}
|
||||
}
|
||||
|
||||
const minMoon = 22;
|
||||
const minStarMoon = 28;
|
||||
|
||||
for (let iter = 0; iter < 40; iter++) {
|
||||
for (let i = 0; i < flat.length; i++) {
|
||||
for (let j = i + 1; j < flat.length; j++) {
|
||||
const d = dist(flat[i].p, flat[j].p);
|
||||
if (d < minMoon && d > 0.001) {
|
||||
const push = (minMoon - d) * 0.55;
|
||||
const ux = (flat[i].p.x - flat[j].p.x) / d;
|
||||
const uy = (flat[i].p.y - flat[j].p.y) / d;
|
||||
flat[i].p.x += ux * push;
|
||||
flat[i].p.y += uy * push;
|
||||
flat[j].p.x -= ux * push;
|
||||
flat[j].p.y -= uy * push;
|
||||
}
|
||||
}
|
||||
const s = stars[flat[i].star];
|
||||
const ds = dist(flat[i].p, s);
|
||||
if (ds < minStarMoon && ds > 0.001) {
|
||||
const ang = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
|
||||
flat[i].p.x = s.x + Math.cos(ang) * minStarMoon;
|
||||
flat[i].p.y = s.y + Math.sin(ang) * minStarMoon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const out = moonsByStar.map((row) => row.map(() => ({ x: 0, y: 0 })));
|
||||
for (const f of flat) {
|
||||
out[f.star][f.moon] = f.p;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function lerpPos(a: Vec2, b: Vec2, t: number): Vec2 {
|
||||
return {
|
||||
x: a.x * t + b.x * (1 - t),
|
||||
|
||||
Reference in New Issue
Block a user