mirror of
https://github.com/Louis-CFM/coucou.git
synced 2026-12-07 07:32:35 +09:00
Memory galaxy: real black hole, round galaxy, soft stars, comets inside
- GalaxyBlackHole.metal: the black hole is computed per pixel on the GPU (light bent by gravity, turning gas disk with differential rotation, Doppler, lensed arcs, photon ring), like the reference video - brain: the galaxy is a round disc (slice per project ∝ memories, same radius for all, soft edges) - galaxy cores and busy stars: soft glow instead of a cross - comets cross the galaxy instead of orbiting far outside - long links are only drawn for the chosen or hovered star Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT
This commit is contained in:
5 files changed
+330
-308
No files matched your search
@@ -0,0 +1,118 @@
|
||||
// The black hole of the Memory › Graph page (you), computed per pixel like Gargantua.
|
||||
// Line-for-line port of BH_GLSL in design/prototype/memory-galaxy.html.
|
||||
// - each pixel sends a light ray bent by gravity (Schwarzschild geodesic, horizon radius 1,
|
||||
// apparent shadow 2.6);
|
||||
// - the accretion disk (3 to 11) is textured gas (fractal noise in a spiral, stretched along the
|
||||
// orbit) that turns: fast inside, slow outside; two layers take turns every 10 s so the spiral
|
||||
// never winds up forever;
|
||||
// - a ray can cross the disk several times: that draws the arc above and below the shadow;
|
||||
// - left side brighter (gas coming toward us, Doppler), hotter and whiter inside;
|
||||
// - elev = disk inclination, follows the camera (thin band from the front, open from the side).
|
||||
// Used as a GraphicsContext fill: `position` and `center` are in Canvas points, `radius` is the
|
||||
// shadow radius in points, `quad` the half side of the filled square in shadow radii.
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <SwiftUI/SwiftUI_Metal.h>
|
||||
using namespace metal;
|
||||
|
||||
namespace galaxybh {
|
||||
|
||||
float hash(float3 p) {
|
||||
p = fract(p * 0.3183099 + 0.1);
|
||||
p *= 17.0;
|
||||
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
|
||||
}
|
||||
|
||||
float noise(float3 x) {
|
||||
float3 i = floor(x), f = fract(x);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
return mix(mix(mix(hash(i), hash(i + float3(1, 0, 0)), f.x),
|
||||
mix(hash(i + float3(0, 1, 0)), hash(i + float3(1, 1, 0)), f.x), f.y),
|
||||
mix(mix(hash(i + float3(0, 0, 1)), hash(i + float3(1, 0, 1)), f.x),
|
||||
mix(hash(i + float3(0, 1, 1)), hash(i + float3(1, 1, 1)), f.x), f.y), f.z);
|
||||
}
|
||||
|
||||
float fbm(float3 p) {
|
||||
float v = 0.0, a = 0.5;
|
||||
for (int i = 0; i < 5; i++) { v += a * noise(p); p = p * 2.03 + 1.7; a *= 0.5; }
|
||||
return v;
|
||||
}
|
||||
|
||||
float modp(float x, float y) { return x - y * floor(x / y); }
|
||||
|
||||
// disk gas, one layer: angle turned by om * lt, a different seed per layer
|
||||
float gas(float phi, float lr, float om, float lt, float seed) {
|
||||
float ph = phi - om * lt + 1.3 * lr;
|
||||
float3 q = float3(cos(ph) * 4.5, sin(ph) * 4.5, lr * 10.0 + seed);
|
||||
q += 0.9 * float3(noise(q * 1.9 + 3.1), noise(q * 1.9 + 7.7), noise(q * 1.9 + 1.3)); // turbulence
|
||||
return fbm(q);
|
||||
}
|
||||
|
||||
float4 disk(float3 p, float3 v, float3 n, float3 e1, float3 e2, float time) {
|
||||
float r = length(p);
|
||||
float edge = smoothstep(2.7, 3.4, r) * (1.0 - smoothstep(5.5, 11.0, r));
|
||||
if (edge <= 0.0) return float4(0.0);
|
||||
float phi = atan2(dot(p, e2), dot(p, e1)), lr = log(r);
|
||||
float om = 0.9 * pow(3.0 / r, 1.5);
|
||||
float T = 10.0, t1 = modp(time, T), t2 = modp(time + T * 0.5, T);
|
||||
float w = abs(t1 / T * 2.0 - 1.0);
|
||||
float d = mix(gas(phi, lr, om, t1, 0.0), gas(phi, lr, om, t2, 37.0), w);
|
||||
d = smoothstep(0.34, 0.8, d);
|
||||
float3 vg = normalize(cross(n, p));
|
||||
float beta = 0.55 * sqrt(3.0 / r), cosa = dot(vg, -v);
|
||||
float D = sqrt(1.0 - beta * beta) / (1.0 - beta * cosa);
|
||||
float I = pow(3.0 / r, 2.0) * edge * pow(D, 3.0) * sqrt(max(0.0, 1.0 - 1.0 / r));
|
||||
float3 col = mix(float3(1.0, 0.86, 0.62), float3(0.8, 0.44, 0.17), smoothstep(3.2, 9.0, r));
|
||||
col = mix(col, float3(1.0, 0.95, 0.86), clamp((D - 1.0) * 0.9, 0.0, 0.8));
|
||||
float mu = max(abs(dot(v, n)), 0.1);
|
||||
float e = I * (0.12 + 1.7 * d) / sqrt(mu);
|
||||
return float4(col * e * 1.15, clamp(e * 1.3, 0.0, 1.0));
|
||||
}
|
||||
|
||||
} // namespace galaxybh
|
||||
|
||||
[[ stitchable ]] half4 galaxyBlackHole(float2 position, float2 center, float radius, float time, float elev, float quad) {
|
||||
using namespace galaxybh;
|
||||
float2 s = (position - center) / radius * 2.6;
|
||||
s.y = -s.y; // screen y goes down, the shader's y goes up
|
||||
float b = length(s);
|
||||
float ce = cos(elev), se = sin(elev);
|
||||
float3 n = float3(0.0, ce, se), e1 = float3(1.0, 0.0, 0.0), e2 = float3(0.0, se, -ce);
|
||||
float3 p = float3(s, 30.0), v = float3(0.0, 0.0, -1.0);
|
||||
float3 h = cross(p, v);
|
||||
float h2 = dot(h, h);
|
||||
float4 acc = float4(0.0);
|
||||
bool captured = false;
|
||||
float side0 = dot(p, n);
|
||||
for (int i = 0; i < 220; i++) {
|
||||
float r = length(p);
|
||||
float dt = clamp(0.07 * r, 0.02, 1.5);
|
||||
v += -1.5 * h2 * p / pow(r, 5.0) * dt;
|
||||
float3 pn = p + v * dt;
|
||||
float side1 = dot(pn, n);
|
||||
if (side0 * side1 < 0.0) {
|
||||
float3 hp = mix(p, pn, side0 / (side0 - side1));
|
||||
float4 c = disk(hp, normalize(v), n, e1, e2, time);
|
||||
acc.rgb += (1.0 - acc.a) * c.rgb;
|
||||
acc.a += (1.0 - acc.a) * c.a;
|
||||
}
|
||||
side0 = side1;
|
||||
p = pn;
|
||||
if (dot(p, p) < 1.0) { captured = true; break; }
|
||||
if (r > 32.0 && dot(p, v) > 0.0) break;
|
||||
if (acc.a > 0.995) break;
|
||||
}
|
||||
// warm halo around the shadow, glow of the band seen from the front (stronger on the left),
|
||||
// thin photon ring straddling the shadow's edge (it also hides the stair steps of that edge)
|
||||
float halo = b > 2.6 ? 0.2 * exp(-(b - 2.6) * 0.8) : 0.0;
|
||||
float band = 0.3 * exp(-abs(s.y) * 1.4) * exp(-abs(s.x) * 0.16) * (1.0 - 0.4 * clamp(s.x * 0.35, -1.0, 1.0)) * max(0.0, 1.0 - sin(elev) * 2.5);
|
||||
float rk = (b - 2.61) * 10.0;
|
||||
float ring = 0.75 * exp(-rk * rk);
|
||||
float g = halo + band + ring;
|
||||
float3 rgb = acc.rgb + (1.0 - acc.a) * float3(1.0, 0.8, 0.55) * g;
|
||||
float a = captured ? 1.0 : acc.a + (1.0 - acc.a) * min(1.0, g) * 0.6;
|
||||
rgb = 1.0 - exp(-rgb * 1.5);
|
||||
if (captured) return half4(half3(rgb), 1.0h);
|
||||
float fade = 1.0 - smoothstep(quad * 2.6 * 0.78, quad * 2.6, b);
|
||||
return half4(half3(rgb * fade), half(a * fade));
|
||||
}
|
||||
@@ -71,6 +71,9 @@ struct GalaxyScene: Sendable {
|
||||
var groups: [GalaxyGroup] = []
|
||||
var rOut: Double = 600
|
||||
var maxAge: Double = 1
|
||||
/// Links longer than 0.22 × the galaxy radius: drawn only when one end is chosen or hovered,
|
||||
/// so no long strokes cross everything (nor the black hole).
|
||||
var edgeLong: [Bool] = []
|
||||
|
||||
static let holeClear = 175.0
|
||||
|
||||
@@ -141,6 +144,10 @@ struct GalaxyScene: Sendable {
|
||||
s.groups[gi].reach = max(s.groups[gi].reach, d)
|
||||
}
|
||||
}
|
||||
let longEdge = 0.22 * s.rOut, nodes = s.nodes
|
||||
s.edgeLong = s.edgeA.indices.map { k in
|
||||
hypot(nodes[s.edgeA[k]].x - nodes[s.edgeB[k]].x, nodes[s.edgeA[k]].y - nodes[s.edgeB[k]].y) > longEdge
|
||||
}
|
||||
return s
|
||||
}
|
||||
}
|
||||
@@ -184,40 +191,6 @@ enum GalaxyTextures {
|
||||
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue),
|
||||
provider: provider, decode: nil, shouldInterpolate: true, intent: .defaultIntent)
|
||||
}()
|
||||
|
||||
/// Accretion disk seen from above: 4 200 golden/brown streaks (PORT buildDisk).
|
||||
static let diskSize = 900.0
|
||||
static let diskR0 = 900.0 / 2 / 3.7
|
||||
static let disk: CGImage? = {
|
||||
let S = Int(diskSize), C = diskSize / 2, R0 = diskR0
|
||||
guard let ctx = CGContext(data: nil, width: S, height: S, bitsPerComponent: 8, bytesPerRow: 0,
|
||||
space: CGColorSpaceCreateDeviceRGB(),
|
||||
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
|
||||
let center = CGPoint(x: C, y: C)
|
||||
let rgb = { (r: Double, g: Double, b: Double, a: Double) in CGColor(red: r / 255, green: g / 255, blue: b / 255, alpha: a) }
|
||||
ctx.saveGState()
|
||||
ctx.addArc(center: center, radius: R0 * 3.7, startAngle: 0, endAngle: .pi * 2, clockwise: false)
|
||||
ctx.addArc(center: center, radius: R0 * 1.35, startAngle: 0, endAngle: .pi * 2, clockwise: false)
|
||||
ctx.clip(using: .evenOdd)
|
||||
if let grad = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(),
|
||||
colors: [rgb(255, 236, 205, 0.7), rgb(240, 190, 130, 0.4), rgb(170, 110, 60, 0.28), rgb(90, 55, 30, 0)] as CFArray,
|
||||
locations: [0, 0.18, 0.5, 1]) {
|
||||
ctx.drawRadialGradient(grad, startCenter: center, startRadius: R0 * 1.35, endCenter: center, endRadius: R0 * 3.7, options: [])
|
||||
}
|
||||
ctx.restoreGState()
|
||||
for _ in 0..<4200 {
|
||||
let r = R0 * (1.38 + pow(Double.random(in: 0..<1), 1.1) * 2.3)
|
||||
let a = Double.random(in: 0..<(2 * .pi)), len = 0.08 + Double.random(in: 0..<0.5)
|
||||
let t = (r / R0 - 1.38) / 2.3
|
||||
let col: (Double, Double, Double) = t < 0.25 ? (255, 238, 210) : t < 0.6 ? (226, 168, 104) : (150, 98, 56)
|
||||
ctx.setStrokeColor(rgb(col.0, col.1, col.2, (0.06 + Double.random(in: 0..<0.26)) * (1 - t * 0.6)))
|
||||
ctx.setLineWidth(0.6 + Double.random(in: 0..<2.2))
|
||||
ctx.beginPath()
|
||||
ctx.addArc(center: center, radius: r, startAngle: a, endAngle: a + len, clockwise: false)
|
||||
ctx.strokePath()
|
||||
}
|
||||
return ctx.makeImage()
|
||||
}()
|
||||
}
|
||||
|
||||
// MARK: - Model
|
||||
@@ -266,13 +239,8 @@ final class GalaxyModel: ObservableObject {
|
||||
let stars: [(x: Double, y: Double, r: Double, a: Double)] = (0..<420).map { _ in
|
||||
(Double.random(in: 0..<1), Double.random(in: 0..<1), Double.random(in: 0.2..<1.1), Double.random(in: 0.15..<0.65))
|
||||
}
|
||||
let dust: [(r: Double, a: Double, s: Double, z: Double)] = (0..<900).map { _ in
|
||||
(1.5 + pow(Double.random(in: 0..<1), 1.2) * 2.1, Double.random(in: 0..<(2 * .pi)), Double.random(in: 0.6..<1.4), Double.random(in: 0..<1))
|
||||
}
|
||||
let arcs: [(r: Double, a0: Double, len: Double, w: Double, sp: Double, al: Double)] = (0..<18).map { _ in
|
||||
(1.06 + Double.random(in: 0..<0.42), Double.random(in: 0..<(2 * .pi)), 1.2 + Double.random(in: 0..<3.8),
|
||||
0.4 + Double.random(in: 0..<1.1), (0.15 + Double.random(in: 0..<0.3)) * (Double.random(in: 0..<1) < 0.85 ? 1 : -1),
|
||||
0.2 + Double.random(in: 0..<0.5))
|
||||
let dust: [(r: Double, a: Double, s: Double, z: Double)] = (0..<700).map { _ in
|
||||
(2.6 + pow(Double.random(in: 0..<1), 1.2) * 4, Double.random(in: 0..<(2 * .pi)), Double.random(in: 0.6..<1.4), Double.random(in: 0..<1))
|
||||
}
|
||||
|
||||
static let graphPath = "\(NSHomeDirectory())/CoucouBrain/.state/graph.json"
|
||||
@@ -330,8 +298,8 @@ final class GalaxyModel: ObservableObject {
|
||||
return (size.width / 2 + x1 * k * f, size.height / 2 + y1 * k * f, f)
|
||||
}
|
||||
|
||||
/// Black hole disk opening: 0.035 seen from the front; opens with |sin yaw| and |sin pitch|.
|
||||
var diskOpen: Double { min(0.62, 0.035 + max(abs(sin(cam.pitch)), abs(sin(cam.yaw)) * 0.75)) }
|
||||
/// Black hole disk opening (sine of its inclination): 0.05 seen from the front; opens with |sin pitch| and |sin yaw|.
|
||||
var diskOpen: Double { min(0.7, 0.05 + max(abs(sin(cam.pitch)) * 0.7, abs(sin(cam.yaw)) * 0.42)) }
|
||||
|
||||
// MARK: Frame step
|
||||
|
||||
@@ -601,7 +569,7 @@ enum GalaxyRenderer {
|
||||
var k = b
|
||||
while k < s.edgeA.count {
|
||||
let a = s.edgeA[k], c = s.edgeB[k]
|
||||
if m.vis[a] && m.vis[c] && s.nodes[a].kind != .moi && s.nodes[c].kind != .moi {
|
||||
if !s.edgeLong[k] && m.vis[a] && m.vis[c] && s.nodes[a].kind != .moi && s.nodes[c].kind != .moi {
|
||||
p.move(to: CGPoint(x: m.px[a], y: m.py[a])); p.addLine(to: CGPoint(x: m.px[c], y: m.py[c]))
|
||||
}
|
||||
k += 3
|
||||
@@ -633,11 +601,11 @@ enum GalaxyRenderer {
|
||||
drawLabels(&ctx, m: m, s: s, bh: bh)
|
||||
}
|
||||
|
||||
// Comets: 5 circles just beyond the galaxy, one turn in 35 to 70 s, continuous trail.
|
||||
// Comets: 5 circles crossing the galaxy (0.45 to 1.05 × its radius), one turn in 35 to 70 s, continuous trail.
|
||||
static func drawOrbits(_ ctx: inout GraphicsContext, now: Double, m: GalaxyModel, s: GalaxyScene) {
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
for k in 0..<5 {
|
||||
let r = s.rOut + 50 + Double(k) * 70
|
||||
let r = s.rOut * (0.45 + Double(k) * 0.15)
|
||||
let sp = (2 * .pi / (35 + Double(k) * 8)) * (k % 2 == 1 ? -1 : 1)
|
||||
let head = Double(k) * 1.3 + now * sp, dir = sp < 0 ? -1.0 : 1.0, len = 1.25, N = 48
|
||||
var pts: [CGPoint] = []
|
||||
@@ -658,12 +626,11 @@ enum GalaxyRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// Sizes follow the hierarchy: galaxy core 1.6 + 0.28·√memories pt with halo and cross;
|
||||
// conversations 0.75 → 1.6 pt; memories 0.55 pt; light cross from 7 links.
|
||||
// Sizes follow the hierarchy: galaxy core 1.6 + 0.28·√memories pt, a soft star (wide halo + bright
|
||||
// glow + core, no cross); conversations 0.75 → 1.6 pt, a small soft halo from 7 links; memories 0.55 pt.
|
||||
static func drawPoints(_ ctx: inout GraphicsContext, now: Double, m: GalaxyModel, s: GalaxyScene) {
|
||||
let W = m.size.width, H = m.size.height, sel = m.selected
|
||||
var buckets: [Int: Path] = [:], people: [Int: Path] = [:]
|
||||
var crosses = Path()
|
||||
for i in s.nodes.indices where m.vis[i] {
|
||||
let n = s.nodes[i], x = m.px[i], y = m.py[i]
|
||||
if x < -40 || y < -40 || x > W + 40 || y > H + 40 { continue }
|
||||
@@ -682,10 +649,12 @@ enum GalaxyRenderer {
|
||||
.init(color: Color(red: 1, green: 236 / 255, blue: 210 / 255).opacity(0.12 * a), location: 0.25),
|
||||
.init(color: Color(red: 1, green: 230 / 255, blue: 200 / 255).opacity(0), location: 1)]),
|
||||
center: CGPoint(x: x, y: y), startRadius: 0, endRadius: r * 6))
|
||||
var c = Path(), L = r * 5
|
||||
c.move(to: CGPoint(x: x - L, y: y)); c.addLine(to: CGPoint(x: x + L, y: y))
|
||||
c.move(to: CGPoint(x: x, y: y - L * 0.8)); c.addLine(to: CGPoint(x: x, y: y + L * 0.8))
|
||||
l.stroke(c, with: .color(Color(red: 1, green: 248 / 255, blue: 236 / 255).opacity(0.4 * a)), lineWidth: 0.8)
|
||||
l.fill(Path(ellipseIn: CGRect(x: x - r * 2.4, y: y - r * 2.4, width: r * 4.8, height: r * 4.8)),
|
||||
with: .radialGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 1, green: 252 / 255, blue: 246 / 255).opacity(0.9 * a), location: 0),
|
||||
.init(color: Color(red: 1, green: 244 / 255, blue: 228 / 255).opacity(0.35 * a), location: 0.45),
|
||||
.init(color: Color(red: 1, green: 240 / 255, blue: 220 / 255).opacity(0), location: 1)]),
|
||||
center: CGPoint(x: x, y: y), startRadius: 0, endRadius: r * 2.4))
|
||||
l.fill(Path(ellipseIn: CGRect(x: x - r, y: y - r, width: r * 2, height: r * 2)), with: .color(Color(red: 1, green: 250 / 255, blue: 242 / 255).opacity(a)))
|
||||
continue
|
||||
}
|
||||
@@ -693,10 +662,11 @@ enum GalaxyRenderer {
|
||||
let key = Int((a * 20).rounded())
|
||||
let dot = Path(ellipseIn: CGRect(x: x - r, y: y - r, width: r * 2, height: r * 2))
|
||||
if n.kind == .personne { people[key, default: Path()].addPath(dot) } else { buckets[key, default: Path()].addPath(dot) }
|
||||
if n.degree >= 7 || i == sel {
|
||||
let L = r * 4.5
|
||||
crosses.move(to: CGPoint(x: x - L, y: y)); crosses.addLine(to: CGPoint(x: x + L, y: y))
|
||||
crosses.move(to: CGPoint(x: x, y: y - L)); crosses.addLine(to: CGPoint(x: x, y: y + L))
|
||||
if n.degree >= 7 { // very connected star: a small soft halo, no cross
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
l.fill(Path(ellipseIn: CGRect(x: x - r * 5, y: y - r * 5, width: r * 10, height: r * 10)),
|
||||
with: .radialGradient(Gradient(colors: [.white.opacity(0.3 * a), .white.opacity(0)]),
|
||||
center: CGPoint(x: x, y: y), startRadius: 0, endRadius: r * 5))
|
||||
}
|
||||
if i == sel {
|
||||
ctx.stroke(Path(ellipseIn: CGRect(x: x - r - 5, y: y - r - 5, width: (r + 5) * 2, height: (r + 5) * 2)), with: .color(.white.opacity(0.85)), lineWidth: 1.1)
|
||||
@@ -704,148 +674,53 @@ enum GalaxyRenderer {
|
||||
}
|
||||
for (k, p) in buckets { ctx.fill(p, with: .color(Color(red: 236 / 255, green: 238 / 255, blue: 243 / 255).opacity(Double(k) / 20))) }
|
||||
for (k, p) in people { ctx.fill(p, with: .color(Color(red: 1, green: 220 / 255, blue: 180 / 255).opacity(Double(k) / 20))) }
|
||||
ctx.stroke(crosses, with: .color(.white.opacity(sel >= 0 ? 0.08 : 0.25)), lineWidth: 0.6)
|
||||
}
|
||||
|
||||
// Black hole (you), from the reference video: Gargantua.
|
||||
// Black hole (you), from the reference video: Gargantua. Computed per pixel on the GPU by
|
||||
// GalaxyBlackHole.metal (light bent by gravity, turning gas disk, Doppler, photon ring);
|
||||
// here only the dust orbiting in the plane of the memory, then the shader fill.
|
||||
static let bhR = 50.0 // shadow radius, in units of the memory plane
|
||||
static let bhQuad = 7.5 // half side of the computed square, in shadow radii
|
||||
|
||||
static func drawBlackHole(_ ctx: inout GraphicsContext, now t: Double, m: GalaxyModel, open: Double) -> (x: Double, y: Double, r: Double) {
|
||||
let p = m.project(0, 0)
|
||||
let bx = p.x, by = p.y, R = 72 * m.scale * p.f
|
||||
let W = m.size.width, H = m.size.height
|
||||
if bx < -R * 6 || by < -R * 6 || bx > W + R * 6 || by > H + R * 6 { return (bx, by, R) }
|
||||
let c = CGPoint(x: bx, y: by)
|
||||
do {
|
||||
let bx = p.x, by = p.y, R = bhR * m.scale * p.f
|
||||
let W = m.size.width, H = m.size.height, Q = bhQuad
|
||||
if bx < -R * Q || by < -R * Q || bx > W + R * Q || by > H + R * Q { return (bx, by, R) }
|
||||
do { // dust orbiting in the plane of the memory (fast near the hole, slower at the edge)
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
// halo
|
||||
let hr = R * (4.5 + open * 2)
|
||||
l.fill(Path(ellipseIn: CGRect(x: bx - hr, y: by - hr, width: hr * 2, height: hr * 2)),
|
||||
with: .radialGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 1, green: 176 / 255, blue: 102 / 255).opacity(0.2 + open * 0.12), location: 0),
|
||||
.init(color: Color(red: 1, green: 140 / 255, blue: 70 / 255).opacity(0.05), location: 0.4),
|
||||
.init(color: .clear, location: 1)]), center: c, startRadius: R * 0.9, endRadius: hr))
|
||||
// dust orbiting in the plane of the memory (fast near the hole, slower at the edge)
|
||||
var buckets: [Int: Path] = [:]
|
||||
for d in m.dust {
|
||||
let a = d.a + t * 1.1 * d.s / pow(d.r, 1.5)
|
||||
let q = m.project(cos(a) * d.r * 72, sin(a) * d.r * 72)
|
||||
let al = (1 - (d.r - 1.5) / 2.2) * (0.2 + d.z * 0.4)
|
||||
let a = d.a + t * 1.1 * d.s / pow(d.r / 1.5, 1.5)
|
||||
let q = m.project(cos(a) * d.r * bhR, sin(a) * d.r * bhR)
|
||||
let al = (1 - (d.r - 2.6) / 4) * (0.15 + d.z * 0.35)
|
||||
buckets[Int((al * 10).rounded()), default: Path()].addRect(CGRect(x: q.x, y: q.y, width: 1.1, height: 1.1))
|
||||
}
|
||||
for (k, path) in buckets { l.fill(path, with: .color(warm(Double(k) / 10, 0.4))) }
|
||||
}
|
||||
let ry = max(0.035, open)
|
||||
drawDiskHalf(&ctx, c: c, R: R, ry: ry, t: t, back: true)
|
||||
do { // lensed rings: the image of the disk bent around the horizon
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
for a in m.arcs {
|
||||
let a0 = a.a0 + t * a.sp, seg = 10
|
||||
let w = a.w * min(2.2, max(0.7, R / 40))
|
||||
for k in 0..<seg {
|
||||
let s0 = a0 + a.len * Double(k) / Double(seg), s1 = a0 + a.len * Double(k + 1) / Double(seg), mid = (s0 + s1) / 2
|
||||
let dop = 0.35 + 0.65 * (0.5 + 0.5 * cos(mid - .pi))
|
||||
var p = Path()
|
||||
p.addArc(center: c, radius: R * a.r, startAngle: .radians(s0), endAngle: .radians(s1), clockwise: false)
|
||||
l.stroke(p, with: .color(warm(a.al * dop * sin(.pi * (Double(k) + 0.5) / Double(seg)) * (1 - open * 0.55), (a.r - 1.06) / 0.42 * 0.8)),
|
||||
style: StrokeStyle(lineWidth: w, lineCap: .butt))
|
||||
}
|
||||
}
|
||||
}
|
||||
// horizon: very dark brown, not pure black
|
||||
ctx.fill(Path(ellipseIn: CGRect(x: bx - R, y: by - R, width: R * 2, height: R * 2)),
|
||||
with: .radialGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 13 / 255, green: 10 / 255, blue: 8 / 255), location: 0),
|
||||
.init(color: Color(red: 22 / 255, green: 16 / 255, blue: 11 / 255), location: 0.75),
|
||||
.init(color: Color(red: 42 / 255, green: 27 / 255, blue: 16 / 255), location: 1)]),
|
||||
center: CGPoint(x: bx - R * 0.15, y: by - R * 0.1), startRadius: 0, endRadius: R))
|
||||
do {
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
l.stroke(Path(ellipseIn: CGRect(x: bx - R * 1.02, y: by - R * 1.02, width: R * 2.04, height: R * 2.04)),
|
||||
with: .color(Color(red: 1, green: 240 / 255, blue: 215 / 255).opacity(0.85)), lineWidth: max(1, R * 0.035))
|
||||
l.stroke(Path(ellipseIn: CGRect(x: bx - R * 0.9, y: by - R * 0.9, width: R * 1.8, height: R * 1.8)),
|
||||
with: .color(Color(red: 1, green: 236 / 255, blue: 210 / 255).opacity(0.3)),
|
||||
style: StrokeStyle(lineWidth: 0.8, dash: [3, 5], dashPhase: -t * 6))
|
||||
}
|
||||
drawDiskHalf(&ctx, c: c, R: R, ry: ry, t: t, back: false)
|
||||
// the horizon stays dark: the part of the disk passing in front of it is only a veil
|
||||
var veil = Path()
|
||||
veil.addArc(center: c, radius: R * 0.99, startAngle: .zero, endAngle: .radians(.pi), clockwise: false)
|
||||
veil.closeSubpath()
|
||||
ctx.fill(veil, with: .linearGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 15 / 255, green: 11 / 255, blue: 8 / 255).opacity(0.94), location: 0),
|
||||
.init(color: Color(red: 15 / 255, green: 11 / 255, blue: 8 / 255).opacity(0.85), location: 0.7),
|
||||
.init(color: Color(red: 15 / 255, green: 11 / 255, blue: 8 / 255).opacity(0.45), location: 1)]),
|
||||
startPoint: c, endPoint: CGPoint(x: bx, y: by + R)))
|
||||
do { // flare on the left
|
||||
var l = ctx; l.blendMode = .plusLighter
|
||||
let fc = CGPoint(x: bx - R, y: by)
|
||||
l.fill(Path(ellipseIn: CGRect(x: fc.x - R * 1.3, y: fc.y - R * 1.3, width: R * 2.6, height: R * 2.6)),
|
||||
with: .radialGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 1, green: 252 / 255, blue: 245 / 255).opacity(0.7), location: 0),
|
||||
.init(color: Color(red: 1, green: 214 / 255, blue: 160 / 255).opacity(0.22), location: 0.3),
|
||||
.init(color: .clear, location: 1)]), center: fc, startRadius: 0, endRadius: R * 1.3))
|
||||
}
|
||||
let square = CGRect(x: bx - R * Q, y: by - R * Q, width: R * Q * 2, height: R * Q * 2)
|
||||
.intersection(CGRect(origin: .zero, size: m.size))
|
||||
guard !square.isEmpty else { return (bx, by, R) }
|
||||
let shader = ShaderLibrary.galaxyBlackHole(
|
||||
.float2(Float(bx), Float(by)),
|
||||
.float(Float(R)),
|
||||
.float(Float(t.truncatingRemainder(dividingBy: 3600))),
|
||||
.float(Float(asin(open))),
|
||||
.float(Float(Q)))
|
||||
ctx.fill(Path(square), with: .shader(shader))
|
||||
return (bx, by, R)
|
||||
}
|
||||
|
||||
static func drawDiskHalf(_ ctx: inout GraphicsContext, c: CGPoint, R: Double, ry: Double, t: Double, back: Bool) {
|
||||
let clip = back ? CGRect(x: c.x - R * 5, y: c.y - R * 5, width: R * 10, height: R * 5)
|
||||
: CGRect(x: c.x - R * 5, y: c.y, width: R * 10, height: R * 5)
|
||||
if let tex = GalaxyTextures.disk {
|
||||
var l = ctx
|
||||
l.clip(to: Path(clip))
|
||||
l.blendMode = .plusLighter
|
||||
l.opacity = min(0.85, 0.5 + ry * 0.7)
|
||||
l.translateBy(x: c.x, y: c.y)
|
||||
l.rotate(by: .radians(-0.03))
|
||||
l.scaleBy(x: 1, y: ry)
|
||||
l.rotate(by: .radians(t * 0.08))
|
||||
let k = R / GalaxyTextures.diskR0, S = GalaxyTextures.diskSize * k
|
||||
l.draw(Image(decorative: tex, scale: 1), in: CGRect(x: -S / 2, y: -S / 2, width: S, height: S))
|
||||
}
|
||||
if ry < 0.2 { // almost closed: the edge shines as a thin band
|
||||
var l = ctx
|
||||
l.clip(to: Path(clip))
|
||||
l.blendMode = .plusLighter
|
||||
l.opacity = (0.2 - ry) / 0.2
|
||||
l.translateBy(x: c.x, y: c.y)
|
||||
l.rotate(by: .radians(-0.03))
|
||||
let L = R * 3.7
|
||||
l.fill(Path(CGRect(x: -L, y: back ? -R * 0.06 : 0, width: 2 * L, height: R * 0.06)),
|
||||
with: .linearGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 1, green: 150 / 255, blue: 80 / 255).opacity(0), location: 0),
|
||||
.init(color: Color(red: 1, green: 214 / 255, blue: 160 / 255).opacity(0.55), location: 0.25),
|
||||
.init(color: Color(red: 1, green: 250 / 255, blue: 240 / 255), location: 0.42),
|
||||
.init(color: Color(red: 1, green: 226 / 255, blue: 186 / 255).opacity(0.8), location: 0.58),
|
||||
.init(color: Color(red: 1, green: 170 / 255, blue: 95 / 255).opacity(0.3), location: 0.82),
|
||||
.init(color: Color(red: 1, green: 140 / 255, blue: 70 / 255).opacity(0), location: 1)]),
|
||||
startPoint: CGPoint(x: -L, y: 0), endPoint: CGPoint(x: L, y: 0)))
|
||||
}
|
||||
do { // left side brighter (Doppler)
|
||||
var l = ctx
|
||||
l.clip(to: Path(clip))
|
||||
l.blendMode = .plusLighter
|
||||
l.translateBy(x: c.x, y: c.y)
|
||||
l.scaleBy(x: 1, y: max(ry, 0.06))
|
||||
var ring = Path(ellipseIn: CGRect(x: -R * 3.6, y: -R * 3.6, width: R * 7.2, height: R * 7.2))
|
||||
ring.addEllipse(in: CGRect(x: -R * 1.35, y: -R * 1.35, width: R * 2.7, height: R * 2.7))
|
||||
l.fill(ring, with: .radialGradient(Gradient(stops: [
|
||||
.init(color: Color(red: 1, green: 244 / 255, blue: 228 / 255).opacity(0.26), location: 0),
|
||||
.init(color: Color(red: 1, green: 200 / 255, blue: 140 / 255).opacity(0), location: 1)]),
|
||||
center: CGPoint(x: -R * 1.3, y: 0), startRadius: 0, endRadius: R * 2.4),
|
||||
style: FillStyle(eoFill: true))
|
||||
}
|
||||
}
|
||||
|
||||
// Names: from afar only the galaxies (under their core: name + "N memories"), moved or hidden if
|
||||
// they overlap; closer, at most 18 titles, never on top of each other.
|
||||
static func drawLabels(_ ctx: inout GraphicsContext, m: GalaxyModel, s: GalaxyScene, bh: (x: Double, y: Double, r: Double)) {
|
||||
m.labelRects = []
|
||||
var taken: [CGRect] = [CGRect(x: bh.x - bh.r * 3.8, y: bh.y - bh.r * 1.6, width: bh.r * 7.6, height: bh.r * 3.4)]
|
||||
var taken: [CGRect] = [CGRect(x: bh.x - bh.r * 4, y: bh.y - bh.r * 2.4, width: bh.r * 8, height: bh.r * 4.8)]
|
||||
func free(_ r: CGRect) -> Bool {
|
||||
if taken.contains(where: { $0.intersects(r) }) { return false }
|
||||
taken.append(r); return true
|
||||
}
|
||||
pill(&ctx, at: CGPoint(x: bh.x, y: bh.y + bh.r * 1.9), text: String(localized: "hub.memory.galaxy.you"))
|
||||
pill(&ctx, at: CGPoint(x: bh.x, y: bh.y + bh.r * 2.7), text: String(localized: "hub.memory.galaxy.you"))
|
||||
let sel = m.selected
|
||||
if m.inGroup < 0 || m.cam.zoom < 2.2 {
|
||||
for gi in s.groups.indices.sorted(by: { s.groups[$0].count > s.groups[$1].count }) {
|
||||
|
||||
+11
-11
@@ -8,10 +8,11 @@
|
||||
*
|
||||
* Everything is FLAT: positions are in the (x, y) plane, z = 0.
|
||||
* - an empty ring around the black hole (HOLE_CLEAR);
|
||||
* - each project owns a sector whose angle ∝ √(its number of points); its depth keeps
|
||||
* the same density (≈ 22² units per point), so big projects reach further out and
|
||||
* the galaxy is not a perfect circle;
|
||||
* - soft edge: radial gaussian jitter σ 18;
|
||||
* - each project owns a sector whose angle ∝ its number of points; every sector reaches the
|
||||
* same radius (density ≈ 22² units per point everywhere), so the galaxy is a round disc
|
||||
* and big projects simply take a wider slice;
|
||||
* - soft edges: radial gaussian jitter σ 18 and angular jitter (σ 0.35 × the slice, at most
|
||||
* 0.12 rad), no empty spokes between projects;
|
||||
* - collision relaxation (min distance 10, 26 around a hub), 24 passes, spatial grid;
|
||||
* - more than 12 projects: the 11 biggest with ≥ 5 points stay, the rest join "Divers".
|
||||
*
|
||||
@@ -24,7 +25,6 @@ import type { GraphData, GraphEdge, GraphNode } from "./graph.js";
|
||||
|
||||
export const HOLE_CLEAR = 175;
|
||||
const DENS = 22 * 22;
|
||||
const GAP = 0.03;
|
||||
const MAX_GROUPS = 12;
|
||||
const MIN_GROUP = 5;
|
||||
export const DIVERS = "Divers";
|
||||
@@ -109,13 +109,13 @@ export function layoutGalaxy(data: GraphData): GraphData {
|
||||
const gIndex = new Map(groups.map((g, i) => [g.name, i]));
|
||||
for (const n of nodes) if (n.kind !== "moi" && n.kind !== "projet") groups[gIndex.get(n.projet!)!].members.push(n.id);
|
||||
groups.sort((a, b) => b.members.length - a.members.length || a.name.localeCompare(b.name));
|
||||
const SQ = groups.reduce((s, g) => s + Math.sqrt(Math.max(1, g.members.length)), 0);
|
||||
const total = groups.reduce((s, g) => s + Math.max(1, g.members.length), 0);
|
||||
const rOut = Math.sqrt(HOLE_CLEAR ** 2 + total * DENS / Math.PI);
|
||||
let acc = -Math.PI / 2;
|
||||
for (const g of groups) {
|
||||
const count = Math.max(1, g.members.length);
|
||||
const span = (2 * Math.PI - GAP * groups.length) * Math.sqrt(count) / SQ;
|
||||
g.a0 = acc; g.a1 = acc + span; acc = g.a1 + GAP;
|
||||
g.rOut = Math.sqrt(HOLE_CLEAR ** 2 + 2 * count * DENS / span);
|
||||
const span = 2 * Math.PI * Math.max(1, g.members.length) / total;
|
||||
g.a0 = acc; g.a1 = acc + span; acc = g.a1;
|
||||
g.rOut = rOut;
|
||||
}
|
||||
|
||||
// ── 4. positions ───────────────────────────────────────────────────────────
|
||||
@@ -132,7 +132,7 @@ export function layoutGalaxy(data: GraphData): GraphData {
|
||||
const n = nById.get(id)!; if (n.kind !== "conv") continue;
|
||||
const r = rng(id);
|
||||
const rho = Math.sqrt(HOLE_CLEAR ** 2 + r() * (g.rOut ** 2 - HOLE_CLEAR ** 2)) + gauss(r) * 18;
|
||||
const th = g.a0 + r() * (g.a1 - g.a0);
|
||||
const th = g.a0 + r() * (g.a1 - g.a0) + gauss(r) * Math.min(0.12, (g.a1 - g.a0) * 0.35);
|
||||
n.x = Math.cos(th) * rho; n.y = Math.sin(th) * rho;
|
||||
}
|
||||
for (const id of g.members) {
|
||||
|
||||
@@ -39,9 +39,14 @@ describe("layoutGalaxy", () => {
|
||||
if (n.kind !== "moi") expect(Math.hypot(n.x, n.y)).toBeGreaterThanOrEqual(HOLE_CLEAR - 0.5);
|
||||
}
|
||||
});
|
||||
it("bigger galaxies reach further out", () => {
|
||||
it("is a round disc: every galaxy reaches the same radius, bigger ones take a wider slice", () => {
|
||||
const far = (name: string) => Math.max(...out.nodes.filter(n => n.projet === name && n.kind === "conv").map(n => Math.hypot(n.x, n.y)));
|
||||
expect(far("p0")).toBeGreaterThan(far("p5"));
|
||||
expect(Math.abs(far("p0") - far("p5")) / far("p0")).toBeLessThan(0.15);
|
||||
const slice = (name: string) => {
|
||||
const a = out.nodes.filter(n => n.projet === name && n.kind === "conv").map(n => Math.atan2(n.y, n.x));
|
||||
return Math.max(...a) - Math.min(...a);
|
||||
};
|
||||
expect(slice("p0")).toBeGreaterThan(slice("p5"));
|
||||
});
|
||||
it("no hub starburst: a hub has at most 8 conversations + moi", () => {
|
||||
for (const h of hubs) expect(out.edges.filter(e => e.from === h.id || e.to === h.id).filter(e => (e.from === "moi" || e.to === "moi") === false).length).toBeLessThanOrEqual(8 + out.nodes.filter(n => n.projet === h.label && n.kind !== "conv" && n.kind !== "projet").length);
|
||||
|
||||
+142
-118
@@ -140,18 +140,18 @@ const addEdge = (a, b) => { if (a === b || nodes[a].adj.includes(b)) return; edg
|
||||
|
||||
// PORT — placement, à plat (plan de la mémoire) autour du trou noir :
|
||||
// - anneau vide autour du trou noir (HOLE_CLEAR) ;
|
||||
// - chaque projet = un secteur dont l'angle ∝ √(nombre de souvenirs) ; sa profondeur est calculée pour
|
||||
// garder la même densité (≈ 22² unités par point) : les gros projets s'étendent plus loin, donc la
|
||||
// galaxie n'est pas un rond parfait, elle a des bras de tailles différentes ;
|
||||
// - bord flou : chaque point reçoit un petit décalage radial gaussien (σ 18).
|
||||
const HOLE_CLEAR = 175, DENS = 22 * 22, GAP = 0.03;
|
||||
// - chaque projet = un secteur dont l'angle ∝ nombre de souvenirs ; tous les secteurs vont jusqu'au même
|
||||
// rayon (densité ≈ 22² unités par point partout) : la galaxie est un disque bien rond, les gros projets
|
||||
// prennent juste une part plus large ;
|
||||
// - bords flous : décalage radial gaussien (σ 18) et angulaire (σ 0,35 × la part), pas de rayons vides.
|
||||
const HOLE_CLEAR = 175, DENS = 22 * 22, GAP = 0;
|
||||
const N_ALL = GROUPS.reduce((s, g) => s + g[1], 0);
|
||||
const SQ = GROUPS.reduce((s, g) => s + Math.sqrt(g[1]), 0);
|
||||
let acc = -Math.PI / 2;
|
||||
GROUPS.forEach(([name, count]) => {
|
||||
const span = (2 * Math.PI - GAP * GROUPS.length) * Math.sqrt(count) / SQ;
|
||||
const span = 2 * Math.PI * count / N_ALL;
|
||||
const a0 = acc, a1 = acc + span; acc = a1 + GAP;
|
||||
const rOut = Math.sqrt(HOLE_CLEAR ** 2 + 2 * count * DENS / span);
|
||||
const rOut = Math.sqrt(HOLE_CLEAR ** 2 + 2 * N_ALL * DENS / (2 * Math.PI));
|
||||
groups.push({ name, count, a0, a1, rOut, ids: [], hub: -1 });
|
||||
});
|
||||
const R_OUT = Math.max(...groups.map(g => g.rOut));
|
||||
@@ -170,7 +170,7 @@ groups.forEach((g, gi) => {
|
||||
let x, y, parent = -1;
|
||||
if (isConv) {
|
||||
const rho = Math.sqrt(HOLE_CLEAR ** 2 + rnd() * (g.rOut ** 2 - HOLE_CLEAR ** 2)) + gauss() * 18;
|
||||
const th = g.a0 + rnd() * (g.a1 - g.a0);
|
||||
const th = g.a0 + rnd() * (g.a1 - g.a0) + gauss() * Math.min(0.12, (g.a1 - g.a0) * 0.35);
|
||||
x = Math.cos(th) * rho; y = Math.sin(th) * rho;
|
||||
} else { parent = convIds[Math.floor(rnd() * convIds.length)]; x = nodes[parent].x + gauss() * 9; y = nodes[parent].y + gauss() * 9; }
|
||||
const id = nodes.length, t = TITLES[g.name];
|
||||
@@ -215,6 +215,9 @@ groups.forEach(g => {
|
||||
[...convs].sort((a, b) => nodes[b].adj.length - nodes[a].adj.length).slice(0, 8).forEach(c => addEdge(g.hub, c));
|
||||
g.ids.filter(i => nodes[i].kind === 'personne').forEach(p => { for (let k = 0; k < 8; k++) addEdge(p, convs[Math.floor(rnd() * convs.length)]); });
|
||||
});
|
||||
// PORT — un lien plus long que 0,22 × le rayon de la galaxie n'est dessiné que quand un de ses bouts est
|
||||
// choisi ou survolé : pas de grands traits qui traversent tout (ni le trou noir).
|
||||
const edgeLong = edges.map(([a, b]) => Math.hypot(nodes[a].x - nodes[b].x, nodes[a].y - nodes[b].y) > 0.22 * R_OUT);
|
||||
const nodeEdges = nodes.map(() => []); edges.forEach(([a, b], k) => { nodeEdges[a].push(k); nodeEdges[b].push(k); });
|
||||
const MAX_AGE = 400;
|
||||
|
||||
@@ -269,120 +272,140 @@ function buildNebula() {
|
||||
const stars = Array.from({ length: 420 }, () => ({ x: Math.random(), y: Math.random(), r: Math.random() * 0.9 + 0.2, a: Math.random() * 0.5 + 0.15 }));
|
||||
|
||||
// ---------- 4. Trou noir (toi) — d'après la vidéo de référence ----------
|
||||
// PORT — le disque d'accrétion est une texture précalculée (milliers de traînées dorées/brunes en
|
||||
// spirale) qui tourne sur elle-même. Son ouverture dépend de la caméra : vu de face il n'est qu'une fine
|
||||
// bande horizontale (Gargantua) ; dès qu'on tourne autour (yaw) ou qu'on passe au-dessus (pitch), il
|
||||
// s'ouvre en grand disque texturé. Moitié arrière avant l'horizon, moitié avant après. Côté gauche plus
|
||||
// brillant. Horizon brun très sombre (pas noir pur), anneau de photons fin et lumineux, anneaux lentillés
|
||||
// fins autour, anneau pointillé intérieur, halo, poussière dans le plan de la mémoire.
|
||||
const BH_R = 72;
|
||||
let diskTex = null;
|
||||
function buildDisk() {
|
||||
const S = 900, c = document.createElement('canvas'); c.width = c.height = S; const g = c.getContext('2d'), C = S / 2, R0 = S / 2 / 3.7;
|
||||
let gr = g.createRadialGradient(C, C, R0 * 1.35, C, C, R0 * 3.7);
|
||||
gr.addColorStop(0, 'rgba(255,236,205,0.7)'); gr.addColorStop(0.18, 'rgba(240,190,130,0.4)'); gr.addColorStop(0.5, 'rgba(170,110,60,0.28)'); gr.addColorStop(1, 'rgba(90,55,30,0)');
|
||||
g.fillStyle = gr; g.beginPath(); g.arc(C, C, R0 * 3.7, 0, 6.283); g.arc(C, C, R0 * 1.35, 0, 6.283, true); g.fill();
|
||||
for (let i = 0; i < 4200; i++) {
|
||||
const r = R0 * (1.38 + Math.pow(Math.random(), 1.1) * 2.3), a = Math.random() * 6.283, len = 0.08 + Math.random() * 0.5;
|
||||
const t = (r / R0 - 1.38) / 2.3;
|
||||
const col = t < 0.25 ? [255, 238, 210] : t < 0.6 ? [226, 168, 104] : [150, 98, 56];
|
||||
g.strokeStyle = `rgba(${col[0]},${col[1]},${col[2]},${(0.06 + Math.random() * 0.26) * (1 - t * 0.6)})`;
|
||||
g.lineWidth = 0.6 + Math.random() * 2.2;
|
||||
g.beginPath(); g.arc(C, C, r, a, a + len); g.stroke();
|
||||
}
|
||||
diskTex = c; diskTex.R0 = R0;
|
||||
// PORT — le trou noir est calculé par un shader (GPU), pixel par pixel, comme Gargantua :
|
||||
// - chaque pixel envoie un rayon de lumière qui est courbé par la gravité (géodésique de Schwarzschild,
|
||||
// rayon de l'horizon = 1, ombre apparente = 2,6) ;
|
||||
// - le disque d'accrétion (de 3 à 16) est du gaz texturé (bruit fractal en spirale, étiré le long de
|
||||
// l'orbite) qui TOURNE : rapide à l'intérieur, lent à l'extérieur. Deux couches se relaient toutes les
|
||||
// 10 s pour que la spirale ne s'enroule pas à l'infini ;
|
||||
// - le rayon peut traverser le disque plusieurs fois : c'est ce qui dessine l'arc lumineux au-dessus et
|
||||
// en dessous de l'ombre et l'anneau de photons, tout seuls ;
|
||||
// - côté gauche plus brillant (le gaz vient vers nous, effet Doppler), centre plus chaud et plus blanc ;
|
||||
// - l'inclinaison du disque suit la caméra (diskOpen) : de face, une bande fine ; de côté ou de
|
||||
// dessus, un grand disque.
|
||||
// Le même shader est en Metal dans le Mac (GalaxyBlackHole.metal).
|
||||
const BH_R = 50; // rayon de l'ombre, en unités du plan de la mémoire
|
||||
const BH_Q = 7.5; // demi-côté du carré calculé, en rayons d'ombre
|
||||
const BH_GLSL = `
|
||||
precision highp float;
|
||||
uniform vec2 uRes; uniform float uTime, uElev, uQ;
|
||||
float hash(vec3 p) { p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }
|
||||
float noise(vec3 x) {
|
||||
vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
|
||||
return mix(mix(mix(hash(i), hash(i + vec3(1, 0, 0)), f.x), mix(hash(i + vec3(0, 1, 0)), hash(i + vec3(1, 1, 0)), f.x), f.y),
|
||||
mix(mix(hash(i + vec3(0, 0, 1)), hash(i + vec3(1, 0, 1)), f.x), mix(hash(i + vec3(0, 1, 1)), hash(i + vec3(1, 1, 1)), f.x), f.y), f.z);
|
||||
}
|
||||
const dust = Array.from({ length: 900 }, () => ({ r: 1.5 + Math.pow(Math.random(), 1.2) * 2.1, a: Math.random() * 6.283, s: 0.6 + Math.random() * 0.8, z: Math.random() }));
|
||||
const arcs = Array.from({ length: 18 }, () => ({ r: 1.06 + Math.random() * 0.42, a0: Math.random() * 6.283, len: 1.2 + Math.random() * 3.8,
|
||||
w: 0.4 + Math.random() * 1.1, sp: (0.00015 + Math.random() * 0.0003) * (Math.random() < 0.85 ? 1 : -1), al: 0.2 + Math.random() * 0.5 }));
|
||||
float fbm(vec3 p) { float v = 0.0, a = 0.5; for (int i = 0; i < 5; i++) { v += a * noise(p); p = p * 2.03 + 1.7; a *= 0.5; } return v; }
|
||||
// gaz du disque, une couche : angle tourné de om * lt, graine différente par couche
|
||||
float gas(float phi, float lr, float om, float lt, float seed) {
|
||||
float ph = phi - om * lt + 1.3 * lr;
|
||||
vec3 q = vec3(cos(ph) * 4.5, sin(ph) * 4.5, lr * 10.0 + seed);
|
||||
q += 0.9 * vec3(noise(q * 1.9 + 3.1), noise(q * 1.9 + 7.7), noise(q * 1.9 + 1.3)); // turbulence
|
||||
return fbm(q);
|
||||
}
|
||||
vec4 disk(vec3 p, vec3 v, vec3 n, vec3 e1, vec3 e2) {
|
||||
float r = length(p);
|
||||
float edge = smoothstep(2.7, 3.4, r) * (1.0 - smoothstep(5.5, 11.0, r));
|
||||
if (edge <= 0.0) return vec4(0.0);
|
||||
float phi = atan(dot(p, e2), dot(p, e1)), lr = log(r);
|
||||
float om = 0.9 * pow(3.0 / r, 1.5);
|
||||
// deux couches qui se relaient (période 10 s) : la rotation reste fluide, sans enroulement infini
|
||||
float T = 10.0, t1 = mod(uTime, T), t2 = mod(uTime + T * 0.5, T);
|
||||
float w = abs(t1 / T * 2.0 - 1.0);
|
||||
float d = mix(gas(phi, lr, om, t1, 0.0), gas(phi, lr, om, t2, 37.0), w);
|
||||
d = smoothstep(0.34, 0.8, d);
|
||||
// Doppler : le gaz qui vient vers nous (à gauche) est plus brillant et plus blanc
|
||||
vec3 vg = normalize(cross(n, p));
|
||||
float beta = 0.55 * sqrt(3.0 / r), cosa = dot(vg, -v);
|
||||
float D = sqrt(1.0 - beta * beta) / (1.0 - beta * cosa);
|
||||
float I = pow(3.0 / r, 2.0) * edge * pow(D, 3.0) * sqrt(max(0.0, 1.0 - 1.0 / r));
|
||||
vec3 col = mix(vec3(1.0, 0.86, 0.62), vec3(0.8, 0.44, 0.17), smoothstep(3.2, 9.0, r));
|
||||
col = mix(col, vec3(1.0, 0.95, 0.86), clamp((D - 1.0) * 0.9, 0.0, 0.8));
|
||||
float mu = max(abs(dot(v, n)), 0.1);
|
||||
float e = I * (0.12 + 1.7 * d) / sqrt(mu);
|
||||
return vec4(col * e * 1.15, clamp(e * 1.3, 0.0, 1.0));
|
||||
}
|
||||
void main() {
|
||||
vec2 uv = gl_FragCoord.xy / uRes * 2.0 - 1.0;
|
||||
vec2 s = uv * uQ * 2.6;
|
||||
float b = length(s);
|
||||
float ce = cos(uElev), se = sin(uElev);
|
||||
vec3 n = vec3(0.0, ce, se), e1 = vec3(1.0, 0.0, 0.0), e2 = vec3(0.0, se, -ce);
|
||||
vec3 p = vec3(s, 30.0), v = vec3(0.0, 0.0, -1.0);
|
||||
vec3 h = cross(p, v); float h2 = dot(h, h);
|
||||
vec4 acc = vec4(0.0);
|
||||
bool captured = false;
|
||||
float side0 = dot(p, n);
|
||||
for (int i = 0; i < 220; i++) {
|
||||
float r = length(p);
|
||||
float dt = clamp(0.07 * r, 0.02, 1.5);
|
||||
v += -1.5 * h2 * p / pow(r, 5.0) * dt;
|
||||
vec3 pn = p + v * dt;
|
||||
float side1 = dot(pn, n);
|
||||
if (side0 * side1 < 0.0) {
|
||||
vec3 hp = mix(p, pn, side0 / (side0 - side1));
|
||||
vec4 c = disk(hp, normalize(v), n, e1, e2);
|
||||
acc.rgb += (1.0 - acc.a) * c.rgb; acc.a += (1.0 - acc.a) * c.a;
|
||||
}
|
||||
side0 = side1; p = pn;
|
||||
if (dot(p, p) < 1.0) { captured = true; break; }
|
||||
if (r > 32.0 && dot(p, v) > 0.0) break;
|
||||
if (acc.a > 0.995) break;
|
||||
}
|
||||
// halo chaud autour de l'ombre + anneau de photons fin
|
||||
// halo chaud autour de l'ombre, lueur de la bande vue de face (plus forte à gauche), anneau de photons
|
||||
// fin à cheval sur le bord de l'ombre (il cache aussi les marches d'escalier du bord)
|
||||
float halo = b > 2.6 ? 0.2 * exp(-(b - 2.6) * 0.8) : 0.0;
|
||||
float band = 0.3 * exp(-abs(s.y) * 1.4) * exp(-abs(s.x) * 0.16) * (1.0 - 0.4 * clamp(s.x * 0.35, -1.0, 1.0)) * max(0.0, 1.0 - sin(uElev) * 2.5);
|
||||
float rk = (b - 2.61) * 10.0; float ring = 0.75 * exp(-rk * rk);
|
||||
float g = halo + band + ring;
|
||||
vec3 rgb = acc.rgb + (1.0 - acc.a) * vec3(1.0, 0.8, 0.55) * g;
|
||||
float a = captured ? 1.0 : acc.a + (1.0 - acc.a) * min(1.0, g) * 0.6;
|
||||
rgb = 1.0 - exp(-rgb * 1.5);
|
||||
float fade = 1.0 - smoothstep(uQ * 2.6 * 0.78, uQ * 2.6, b);
|
||||
if (captured) { gl_FragColor = vec4(rgb, 1.0); return; }
|
||||
gl_FragColor = vec4(rgb, a) * fade;
|
||||
}`;
|
||||
let bhGL = null;
|
||||
function initBH() {
|
||||
const c = document.createElement('canvas'), gl = c.getContext('webgl', { premultipliedAlpha: true, alpha: true });
|
||||
const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(s)); return s; };
|
||||
const pr = gl.createProgram();
|
||||
gl.attachShader(pr, sh(gl.VERTEX_SHADER, 'attribute vec2 a; void main(){ gl_Position = vec4(a, 0.0, 1.0); }'));
|
||||
gl.attachShader(pr, sh(gl.FRAGMENT_SHADER, BH_GLSL)); gl.linkProgram(pr); gl.useProgram(pr);
|
||||
const buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
|
||||
const loc = gl.getAttribLocation(pr, 'a'); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
|
||||
bhGL = { c, gl, u: { res: gl.getUniformLocation(pr, 'uRes'), time: gl.getUniformLocation(pr, 'uTime'), elev: gl.getUniformLocation(pr, 'uElev'), q: gl.getUniformLocation(pr, 'uQ') } };
|
||||
}
|
||||
const dust = Array.from({ length: 700 }, () => ({ r: 2.6 + Math.pow(Math.random(), 1.2) * 4, a: Math.random() * 6.283, s: 0.6 + Math.random() * 0.8, z: Math.random() }));
|
||||
function drawBlackHole(t, open) {
|
||||
project(0, 0, 0, tmp);
|
||||
const bx = tmp[0], by = tmp[1], R = BH_R * scale() * tmp[2];
|
||||
const warm = (a, k = 0) => `rgba(255,${226 - k * 60 | 0},${186 - k * 110 | 0},${a})`;
|
||||
if (bx < -R * 6 || by < -R * 6 || bx > W + R * 6 || by > H + R * 6) return { bx, by, R };
|
||||
// halo
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
let g = ctx.createRadialGradient(bx, by, R * 0.9, bx, by, R * (4.5 + open * 2));
|
||||
g.addColorStop(0, `rgba(255,176,102,${0.2 + open * 0.12})`); g.addColorStop(0.4, 'rgba(255,140,70,0.05)'); g.addColorStop(1, 'rgba(0,0,0,0)');
|
||||
ctx.fillStyle = g; ctx.fillRect(bx - R * 7, by - R * 7, R * 14, R * 14);
|
||||
if (bx < -R * BH_Q || by < -R * BH_Q || bx > W + R * BH_Q || by > H + R * BH_Q) return { bx, by, R };
|
||||
// poussière en orbite dans le plan de la mémoire (rapide près du trou noir, plus lente au bord)
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
for (const d of dust) {
|
||||
const a = d.a + t * 0.0011 * d.s / Math.pow(d.r, 1.5);
|
||||
const a = d.a + t * 0.0011 * d.s / Math.pow(d.r / 1.5, 1.5);
|
||||
project(Math.cos(a) * d.r * BH_R, Math.sin(a) * d.r * BH_R, 0, tmp);
|
||||
ctx.fillStyle = warm((1 - (d.r - 1.5) / 2.2) * (0.2 + d.z * 0.4), d.z); ctx.fillRect(tmp[0], tmp[1], 1.1 * DPR, 1.1 * DPR);
|
||||
ctx.fillStyle = `rgba(255,${214 - d.z * 40 | 0},${170 - d.z * 70 | 0},${(1 - (d.r - 2.6) / 4) * (0.15 + d.z * 0.35)})`; ctx.fillRect(tmp[0], tmp[1], 1.1 * DPR, 1.1 * DPR);
|
||||
}
|
||||
ctx.restore();
|
||||
// disque : moitié arrière (au-dessus), derrière l'horizon
|
||||
const ry = Math.max(0.035, open);
|
||||
drawDiskHalf(bx, by, R, ry, t, true);
|
||||
// anneaux lentillés (l'image du disque courbée autour de l'horizon), plus visibles quand le disque est fermé
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
for (const c of arcs) {
|
||||
const a0 = c.a0 + t * c.sp, seg = 10;
|
||||
ctx.lineWidth = c.w * DPR * Math.min(2.2, Math.max(0.7, R / 40)); ctx.lineCap = 'butt';
|
||||
for (let k = 0; k < seg; k++) {
|
||||
const s0 = a0 + c.len * k / seg, s1 = a0 + c.len * (k + 1) / seg, mid = (s0 + s1) / 2;
|
||||
const dop = 0.35 + 0.65 * (0.5 + 0.5 * Math.cos(mid - Math.PI));
|
||||
ctx.strokeStyle = warm(c.al * dop * Math.sin(Math.PI * (k + 0.5) / seg) * (1 - open * 0.55), (c.r - 1.06) / 0.42 * 0.8);
|
||||
ctx.beginPath(); ctx.arc(bx, by, R * c.r, s0, s1); ctx.stroke();
|
||||
}
|
||||
}
|
||||
ctx.restore();
|
||||
// horizon : brun très sombre, pas noir pur
|
||||
g = ctx.createRadialGradient(bx - R * 0.15, by - R * 0.1, 0, bx, by, R);
|
||||
g.addColorStop(0, '#0d0a08'); g.addColorStop(0.75, '#16100b'); g.addColorStop(1, '#2a1b10');
|
||||
ctx.fillStyle = g; ctx.beginPath(); ctx.arc(bx, by, R, 0, 6.283); ctx.fill();
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
// anneau de photons
|
||||
ctx.strokeStyle = 'rgba(255,240,215,0.85)'; ctx.lineWidth = Math.max(1, R * 0.035); ctx.beginPath(); ctx.arc(bx, by, R * 1.02, 0, 6.283); ctx.stroke();
|
||||
// anneau pointillé intérieur qui tourne
|
||||
ctx.setLineDash([3 * DPR, 5 * DPR]); ctx.lineDashOffset = -t * 0.006 * DPR;
|
||||
ctx.strokeStyle = 'rgba(255,236,210,0.3)'; ctx.lineWidth = 0.8 * DPR; ctx.beginPath(); ctx.arc(bx, by, R * 0.9, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
|
||||
ctx.restore();
|
||||
// disque : moitié avant (en dessous), devant l'horizon
|
||||
drawDiskHalf(bx, by, R, ry, t, false);
|
||||
// l'horizon reste sombre : la partie du disque qui passe devant lui n'est qu'un voile
|
||||
ctx.save(); ctx.beginPath(); ctx.arc(bx, by, R * 0.99, 0, Math.PI); ctx.closePath(); const vg = ctx.createLinearGradient(0, by, 0, by + R); vg.addColorStop(0, 'rgba(15,11,8,0.94)'); vg.addColorStop(0.7, 'rgba(15,11,8,0.85)'); vg.addColorStop(1, 'rgba(15,11,8,0.45)'); ctx.fillStyle = vg; ctx.fill(); ctx.restore();
|
||||
// éclat côté gauche
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
g = ctx.createRadialGradient(bx - R * 1.0, by, 0, bx - R * 1.0, by, R * 1.3);
|
||||
g.addColorStop(0, 'rgba(255,252,245,0.7)'); g.addColorStop(0.3, 'rgba(255,214,160,0.22)'); g.addColorStop(1, 'rgba(255,170,90,0)');
|
||||
ctx.fillStyle = g; ctx.fillRect(bx - R * 2.4, by - R * 1.4, R * 2.8, R * 2.8);
|
||||
ctx.restore();
|
||||
if (!bhGL) initBH();
|
||||
const half = R * BH_Q, px = Math.min(1024, Math.ceil(half * 2));
|
||||
const { c, gl, u } = bhGL;
|
||||
if (c.width !== px) { c.width = c.height = px; }
|
||||
gl.viewport(0, 0, px, px);
|
||||
gl.uniform2f(u.res, px, px); gl.uniform1f(u.time, (t / 1000) % 3600); gl.uniform1f(u.elev, Math.asin(open)); gl.uniform1f(u.q, BH_Q);
|
||||
gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
ctx.drawImage(c, bx - half, by - half, half * 2, half * 2);
|
||||
return { bx, by, R };
|
||||
}
|
||||
function drawDiskHalf(bx, by, R, ry, t, back) {
|
||||
if (!diskTex) buildDisk();
|
||||
const S = diskTex.width, k = R / diskTex.R0;
|
||||
ctx.save();
|
||||
ctx.beginPath(); back ? ctx.rect(bx - R * 5, by - R * 5, R * 10, R * 5) : ctx.rect(bx - R * 5, by, R * 10, R * 5); ctx.clip();
|
||||
ctx.translate(bx, by); ctx.rotate(-0.03); ctx.scale(1, ry); ctx.rotate(t * 0.00008);
|
||||
ctx.globalCompositeOperation = 'lighter';
|
||||
ctx.globalAlpha = Math.min(0.85, 0.5 + ry * 0.7);
|
||||
ctx.drawImage(diskTex, -S / 2 * k, -S / 2 * k, S * k, S * k);
|
||||
// une fois le disque presque fermé, la tranche brille comme une bande fine
|
||||
if (ry < 0.2) {
|
||||
ctx.globalAlpha = (0.2 - ry) / 0.2;
|
||||
const L = R * 3.7, lg = ctx.createLinearGradient(-L, 0, L, 0);
|
||||
lg.addColorStop(0, 'rgba(255,150,80,0)'); lg.addColorStop(0.25, 'rgba(255,214,160,0.55)'); lg.addColorStop(0.42, 'rgba(255,250,240,1)');
|
||||
lg.addColorStop(0.58, 'rgba(255,226,186,0.8)'); lg.addColorStop(0.82, 'rgba(255,170,95,0.3)'); lg.addColorStop(1, 'rgba(255,140,70,0)');
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.translate(bx, by); ctx.rotate(-0.03);
|
||||
ctx.fillStyle = lg; ctx.fillRect(-L, back ? -R * 0.06 : 0, 2 * L, R * 0.06);
|
||||
}
|
||||
ctx.restore();
|
||||
// côté gauche plus brillant (Doppler)
|
||||
ctx.save(); ctx.beginPath(); back ? ctx.rect(bx - R * 5, by - R * 5, R * 10, R * 5) : ctx.rect(bx - R * 5, by, R * 10, R * 5); ctx.clip();
|
||||
ctx.translate(bx, by); ctx.scale(1, Math.max(ry, 0.06)); ctx.globalCompositeOperation = 'lighter';
|
||||
const dg = ctx.createRadialGradient(-R * 1.3, 0, 0, -R * 1.3, 0, R * 2.4);
|
||||
dg.addColorStop(0, 'rgba(255,244,228,0.26)'); dg.addColorStop(1, 'rgba(255,200,140,0)');
|
||||
ctx.fillStyle = dg; ctx.beginPath(); ctx.arc(0, 0, R * 3.6, 0, 6.283); ctx.arc(0, 0, R * 1.35, 0, 6.283, true); ctx.fill();
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// ---------- 5. Comètes : orbites à plat autour de la galaxie ----------
|
||||
// PORT — 5 comètes sur des cercles juste au-delà de la galaxie, un tour en 35 à 70 s ; traînée continue
|
||||
// PORT — 5 comètes sur des cercles qui traversent la galaxie (0,45 à 1,05 × son rayon), un tour en 35 à 70 s ; traînée continue
|
||||
// (segments sans bouts arrondis, aucun point visible dans la ligne), tête brillante.
|
||||
const orbits = [0, 1, 2, 3, 4].map(k => ({ r: R_OUT + 50 + k * 70, sp: (2 * Math.PI / (35000 + k * 8000)) * (k % 2 ? -1 : 1), a0: k * 1.3 }));
|
||||
const orbits = [0, 1, 2, 3, 4].map(k => ({ r: R_OUT * (0.45 + k * 0.15), sp: (2 * Math.PI / (35000 + k * 8000)) * (k % 2 ? -1 : 1), a0: k * 1.3 }));
|
||||
function drawOrbits(t) {
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter'; ctx.lineCap = 'butt'; ctx.lineJoin = 'round';
|
||||
for (const o of orbits) {
|
||||
@@ -412,8 +435,8 @@ function newSignal(from) {
|
||||
else { e = Math.floor(Math.random() * edges.length); a = edges[e][Math.random() < 0.5 ? 0 : 1]; }
|
||||
return { a, b: edges[e][0] === a ? edges[e][1] : edges[e][0], t: from == null ? Math.random() : 0, sp: 0.005 + Math.random() * 0.009, hops: 3 + Math.floor(Math.random() * 5) };
|
||||
}
|
||||
// PORT — ouverture du disque du trou noir : 0,035 de face ; s'ouvre avec |sin yaw| et |sin pitch|.
|
||||
const diskOpen = () => Math.min(0.62, 0.035 + Math.max(Math.abs(Math.sin(cam.pitch)), Math.abs(Math.sin(cam.yaw)) * 0.75));
|
||||
// PORT — ouverture du disque du trou noir (sinus de son inclinaison) : 0,05 de face ; s'ouvre avec |sin yaw| et |sin pitch|.
|
||||
const diskOpen = () => Math.min(0.7, 0.05 + Math.max(Math.abs(Math.sin(cam.pitch)) * 0.7, Math.abs(Math.sin(cam.yaw)) * 0.42));
|
||||
|
||||
function frame(now) {
|
||||
const dt = Math.min(50, now - last); last = now; fpsAcc += dt; fpsN++;
|
||||
@@ -451,7 +474,7 @@ function frame(now) {
|
||||
ctx.lineWidth = 0.6 * DPR;
|
||||
for (let b = 0; b < 3; b++) {
|
||||
ctx.strokeStyle = `rgba(255,255,255,${base * (0.62 + 0.38 * Math.sin(now * 0.0011 + b * 2.1))})`; ctx.beginPath();
|
||||
for (let k = b; k < edges.length; k += 3) { const [a, c] = edges[k]; if (!vis[a] || !vis[c]) continue; ctx.moveTo(P[a * 3], P[a * 3 + 1]); ctx.lineTo(P[c * 3], P[c * 3 + 1]); }
|
||||
for (let k = b; k < edges.length; k += 3) { const [a, c] = edges[k]; if (edgeLong[k] || !vis[a] || !vis[c]) continue; ctx.moveTo(P[a * 3], P[a * 3 + 1]); ctx.lineTo(P[c * 3], P[c * 3 + 1]); }
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter'; ctx.lineCap = 'butt';
|
||||
@@ -479,8 +502,8 @@ function frame(now) {
|
||||
ctx.textAlign = 'center';
|
||||
const taken = [];
|
||||
const free = (x, y, w, h) => { for (const r of taken) if (x < r[0] + r[2] && x + w > r[0] && y < r[1] + r[3] && y + h > r[1]) return false; taken.push([x, y, w, h]); return true; };
|
||||
taken.push([bh.bx - bh.R * 3.8, bh.by - bh.R * 1.6, bh.R * 7.6, bh.R * 3.4]);
|
||||
pillLabel(bh.bx, bh.by + bh.R * 1.9, 'Toi');
|
||||
taken.push([bh.bx - bh.R * 4, bh.by - bh.R * 2.4, bh.R * 8, bh.R * 4.8]);
|
||||
pillLabel(bh.bx, bh.by + bh.R * 2.7, 'Toi');
|
||||
if (inGroup < 0 || cam.zoom < 2.2) [...groups.keys()].sort((a, b) => groups[b].count - groups[a].count).forEach(gi => {
|
||||
const g = groups[gi], i = g.hub; if (!vis[i]) return;
|
||||
const x = P[i * 3]; let y = P[i * 3 + 1] + 20 * DPR;
|
||||
@@ -537,17 +560,18 @@ function drawPoints(now) {
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
const g = ctx.createRadialGradient(x, y, 0, x, y, r * 6); g.addColorStop(0, `rgba(255,246,232,${0.45 * a})`); g.addColorStop(0.25, `rgba(255,236,210,${0.12 * a})`); g.addColorStop(1, 'rgba(255,230,200,0)');
|
||||
ctx.fillStyle = g; ctx.fillRect(x - r * 6, y - r * 6, r * 12, r * 12);
|
||||
ctx.strokeStyle = `rgba(255,248,236,${0.4 * a})`; ctx.lineWidth = 0.8 * DPR; const L = r * 5;
|
||||
ctx.beginPath(); ctx.moveTo(x - L, y); ctx.lineTo(x + L, y); ctx.moveTo(x, y - L * 0.8); ctx.lineTo(x, y + L * 0.8); ctx.stroke();
|
||||
const g2 = ctx.createRadialGradient(x, y, 0, x, y, r * 2.4); g2.addColorStop(0, `rgba(255,252,246,${0.9 * a})`); g2.addColorStop(0.45, `rgba(255,244,228,${0.35 * a})`); g2.addColorStop(1, 'rgba(255,240,220,0)');
|
||||
ctx.fillStyle = g2; ctx.fillRect(x - r * 2.4, y - r * 2.4, r * 4.8, r * 4.8);
|
||||
ctx.fillStyle = `rgba(255,250,242,${a})`; ctx.beginPath(); ctx.arc(x, y, r, 0, 6.283); ctx.fill();
|
||||
ctx.restore(); continue;
|
||||
}
|
||||
const r = (n.kind === 'conv' || n.kind === 'personne' ? 0.75 + Math.min(0.85, deg * 0.08) : 0.55) * DPR * zf;
|
||||
ctx.fillStyle = n.kind === 'personne' ? `rgba(255,220,180,${a})` : `rgba(236,238,243,${a})`;
|
||||
ctx.beginPath(); ctx.arc(x, y, r, 0, 6.283); ctx.fill();
|
||||
if (deg >= 7 || i === sel) {
|
||||
ctx.strokeStyle = `rgba(255,255,255,${a * 0.35})`; ctx.lineWidth = 0.6 * DPR; const L = r * 4.5;
|
||||
ctx.beginPath(); ctx.moveTo(x - L, y); ctx.lineTo(x + L, y); ctx.moveTo(x, y - L); ctx.lineTo(x, y + L); ctx.stroke();
|
||||
if (deg >= 7) { // étoile très reliée : petit halo doux, pas de croix
|
||||
ctx.save(); ctx.globalCompositeOperation = 'lighter';
|
||||
const g = ctx.createRadialGradient(x, y, 0, x, y, r * 5); g.addColorStop(0, `rgba(255,255,255,${0.3 * a})`); g.addColorStop(1, 'rgba(255,255,255,0)');
|
||||
ctx.fillStyle = g; ctx.fillRect(x - r * 5, y - r * 5, r * 10, r * 10); ctx.restore();
|
||||
}
|
||||
if (i === sel) { ctx.strokeStyle = 'rgba(255,255,255,.85)'; ctx.lineWidth = 1.1 * DPR; ctx.beginPath(); ctx.arc(x, y, r + 5 * DPR, 0, 6.283); ctx.stroke(); }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user