Video: voxel titles, new opening with world turn, app punch-ins and callouts, six-screen montage, props sequence; site carries the new film
This commit is contained in:
37 files changed
+2672
-165
No files matched your search
@@ -0,0 +1,246 @@
|
||||
// Orthographic boxes turning about the desk's vertical axis.
|
||||
|
||||
const COS = Math.cos(Math.PI / 6);
|
||||
const SIN = Math.sin(Math.PI / 6);
|
||||
const EPS = 1e-6;
|
||||
|
||||
/** A box in grid units, with its light tone. */
|
||||
export interface Box {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
w: number;
|
||||
d: number;
|
||||
h: number;
|
||||
tone: string;
|
||||
}
|
||||
|
||||
/** A box as drawn: alpha and seam stroke. */
|
||||
export interface Shown {
|
||||
box: Box;
|
||||
alpha: number;
|
||||
seam?: boolean;
|
||||
}
|
||||
|
||||
/** World turn and the camera's scale and offset. */
|
||||
export interface View {
|
||||
turn: number;
|
||||
cx: number;
|
||||
cy: number;
|
||||
s: number;
|
||||
ox: number;
|
||||
oy: number;
|
||||
}
|
||||
|
||||
type Point = [number, number];
|
||||
|
||||
/** Grid point to frame pixels. */
|
||||
export function project(v: View, x: number, y: number, z: number): Point {
|
||||
const [c, s] = [Math.cos(v.turn), Math.sin(v.turn)];
|
||||
const [dx, dy] = [x - v.cx, y - v.cy];
|
||||
const X = c * dx - s * dy;
|
||||
const Y = s * dx + c * dy;
|
||||
return [v.ox + v.s * (X - Y) * COS, v.oy + v.s * ((X + Y) * SIN - z)];
|
||||
}
|
||||
|
||||
/** Frame pixel to the ground plane at height z. */
|
||||
export function ground(v: View, px: number, py: number, z = 0): Point {
|
||||
const a = (px - v.ox) / (v.s * COS);
|
||||
const b = ((py - v.oy) / v.s + z) / SIN;
|
||||
const [X, Y] = [(a + b) / 2, (b - a) / 2];
|
||||
const [c, s] = [Math.cos(v.turn), Math.sin(v.turn)];
|
||||
return [v.cx + c * X + s * Y, v.cy - s * X + c * Y];
|
||||
}
|
||||
|
||||
/** Hex colour to linear oklab. */
|
||||
function oklab(hex: string): [number, number, number] {
|
||||
const n = parseInt(hex.slice(1), 16);
|
||||
const lin = (u: number) => (u <= 0.04045 ? u / 12.92 : ((u + 0.055) / 1.055) ** 2.4);
|
||||
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((u) => lin(u / 255));
|
||||
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
||||
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
||||
const q = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
||||
return [
|
||||
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * q,
|
||||
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * q,
|
||||
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * q,
|
||||
];
|
||||
}
|
||||
|
||||
function rgb([L, A, B]: [number, number, number]): string {
|
||||
const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
||||
const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
||||
const q = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
||||
const out = [
|
||||
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * q,
|
||||
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * q,
|
||||
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * q,
|
||||
].map((u) => {
|
||||
const c = Math.min(1, Math.max(0, u));
|
||||
const s = c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055;
|
||||
return Math.round(s * 255);
|
||||
});
|
||||
return `rgb(${out.join(",")})`;
|
||||
}
|
||||
|
||||
const shades = new Map<string, string>();
|
||||
|
||||
/** A tone mixed toward black by `k`, in oklab. */
|
||||
export function shade(hex: string, k: number): string {
|
||||
const key = `${hex}:${k.toFixed(3)}`;
|
||||
let found = shades.get(key);
|
||||
if (!found) {
|
||||
found = rgb(oklab(hex).map((u) => u * (1 - k)) as [number, number, number]);
|
||||
shades.set(key, found);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/** Two tones mixed in oklab. */
|
||||
export function mix(a: string, b: string, u: number): string {
|
||||
const [p, q] = [oklab(a), oklab(b)];
|
||||
return rgb(p.map((v, i) => v + (q[i] - v) * u) as [number, number, number]);
|
||||
}
|
||||
|
||||
/** Side darkness: 9% facing +y, 20% facing +x. */
|
||||
function darkness(nx: number, ny: number): number {
|
||||
return 0.145 - 0.0778 * Math.cos(Math.atan2(ny, nx) - (3 * Math.PI) / 4);
|
||||
}
|
||||
|
||||
function hull(points: Point[]): Point[] {
|
||||
const p = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
||||
const cross = (o: Point, a: Point, b: Point) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
||||
const half = (list: Point[]) => {
|
||||
const out: Point[] = [];
|
||||
for (const q of list) {
|
||||
while (out.length >= 2 && cross(out[out.length - 2], out[out.length - 1], q) <= 0) out.pop();
|
||||
out.push(q);
|
||||
}
|
||||
out.pop();
|
||||
return out;
|
||||
};
|
||||
return [...half(p), ...half([...p].reverse())];
|
||||
}
|
||||
|
||||
function fill(ctx: CanvasRenderingContext2D, pts: Point[], color: string, seam = 0) {
|
||||
ctx.beginPath();
|
||||
pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)));
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
if (seam) {
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = seam;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
/** One box: silhouette, then its visible faces. */
|
||||
function paint(ctx: CanvasRenderingContext2D, v: View, { box: b, alpha, seam }: Shown) {
|
||||
if (b.h <= EPS || alpha <= 0) return;
|
||||
const p = (i: number, j: number, k: number) => project(v, b.x + i * b.w, b.y + j * b.d, b.z + k * b.h);
|
||||
const [c, s] = [Math.cos(v.turn), Math.sin(v.turn)];
|
||||
const sides: [number, number, Point[]][] = [
|
||||
[1, 0, [p(1, 0, 0), p(1, 1, 0), p(1, 1, 1), p(1, 0, 1)]],
|
||||
[-1, 0, [p(0, 0, 0), p(0, 1, 0), p(0, 1, 1), p(0, 0, 1)]],
|
||||
[0, 1, [p(0, 1, 0), p(1, 1, 0), p(1, 1, 1), p(0, 1, 1)]],
|
||||
[0, -1, [p(0, 0, 0), p(1, 0, 0), p(1, 0, 1), p(0, 0, 1)]],
|
||||
];
|
||||
const seen = sides.flatMap(([x, y, pts]) => {
|
||||
const [nx, ny] = [c * x - s * y, s * x + c * y];
|
||||
return nx + ny > EPS ? [{ pts, k: darkness(nx, ny) }] : [];
|
||||
});
|
||||
ctx.globalAlpha = alpha;
|
||||
if (alpha >= 1) {
|
||||
const all = [0, 1].flatMap((i) => [0, 1].flatMap((j) => [0, 1].map((k) => p(i, j, k))));
|
||||
fill(ctx, hull(all), shade(b.tone, Math.max(...seen.map((f) => f.k))));
|
||||
}
|
||||
for (const f of seen) fill(ctx, f.pts, shade(b.tone, f.k), seam ? 1 : 0);
|
||||
fill(ctx, [p(0, 0, 1), p(1, 0, 1), p(1, 1, 1), p(0, 1, 1)], b.tone, seam ? 1.2 : 0);
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
|
||||
function bounds(v: View, b: Box): [number, number, number, number] {
|
||||
let [x0, x1, y0, y1] = [Infinity, -Infinity, Infinity, -Infinity];
|
||||
for (const i of [0, 1])
|
||||
for (const j of [0, 1])
|
||||
for (const k of [0, 1]) {
|
||||
const [x, y] = project(v, b.x + i * b.w, b.y + j * b.d, b.z + k * b.h);
|
||||
[x0, x1, y0, y1] = [Math.min(x0, x), Math.max(x1, x), Math.min(y0, y), Math.max(y1, y)];
|
||||
}
|
||||
return [x0, x1, y0, y1];
|
||||
}
|
||||
|
||||
/** True if `a` draws first, false if `b`, null if unknown. */
|
||||
function behind(a: Box, b: Box, vx: number, vy: number): boolean | null {
|
||||
const axes: [number, number, number, number, number][] = [
|
||||
[a.x, a.w, b.x, b.w, vx],
|
||||
[a.y, a.d, b.y, b.d, vy],
|
||||
[a.z, a.h, b.z, b.h, 1],
|
||||
];
|
||||
for (const [p, pw, q, qw, dir] of axes) {
|
||||
if (Math.abs(dir) < EPS) continue;
|
||||
if (p + pw <= q + EPS) return dir > 0;
|
||||
if (q + qw <= p + EPS) return dir < 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Nearest bottom corner's depth toward the viewer. */
|
||||
function depth(v: View, b: Box): number {
|
||||
const [c, s] = [Math.cos(v.turn), Math.sin(v.turn)];
|
||||
let best = -Infinity;
|
||||
for (const i of [0, 1])
|
||||
for (const j of [0, 1]) {
|
||||
const [dx, dy] = [b.x + i * b.w - v.cx, b.y + j * b.d - v.cy];
|
||||
best = Math.max(best, (c + s) * dx + (c - s) * dy);
|
||||
}
|
||||
return best + b.z;
|
||||
}
|
||||
|
||||
/** Back to front: overlaps decide, depth breaks ties. */
|
||||
function order(v: View, list: Shown[]): Shown[] {
|
||||
const [c, s] = [Math.cos(v.turn), Math.sin(v.turn)];
|
||||
const [vx, vy] = [c + s, c - s];
|
||||
const rects = list.map((e) => bounds(v, e.box));
|
||||
const keys = list.map((e) => depth(v, e.box));
|
||||
const after: number[][] = list.map(() => []);
|
||||
const waits = list.map(() => 0);
|
||||
for (let i = 0; i < list.length; i++)
|
||||
for (let j = i + 1; j < list.length; j++) {
|
||||
const [a, b] = [rects[i], rects[j]];
|
||||
if (a[1] <= b[0] + 0.5 || b[1] <= a[0] + 0.5 || a[3] <= b[2] + 0.5 || b[3] <= a[2] + 0.5) continue;
|
||||
const first = behind(list[i].box, list[j].box, vx, vy);
|
||||
if (first === null) continue;
|
||||
const [from, to] = first ? [i, j] : [j, i];
|
||||
after[from].push(to);
|
||||
waits[to]++;
|
||||
}
|
||||
const out: Shown[] = [];
|
||||
const done = list.map(() => false);
|
||||
while (out.length < list.length) {
|
||||
let next = -1;
|
||||
for (let i = 0; i < list.length; i++)
|
||||
if (!done[i] && waits[i] === 0 && (next < 0 || keys[i] < keys[next])) next = i;
|
||||
if (next < 0) {
|
||||
for (let i = 0; i < list.length; i++) if (!done[i] && (next < 0 || keys[i] < keys[next])) next = i;
|
||||
waits[next] = 0;
|
||||
}
|
||||
done[next] = true;
|
||||
out.push(list[next]);
|
||||
for (const k of after[next]) waits[k]--;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Draws every box in painter's order. */
|
||||
export function boxes(ctx: CanvasRenderingContext2D, v: View, list: Shown[]): void {
|
||||
for (const e of order(v, list)) paint(ctx, v, e);
|
||||
}
|
||||
|
||||
/** A ground cell's diamond, squashed about its centre. */
|
||||
export function cell(ctx: CanvasRenderingContext2D, v: View, i: number, j: number, u: number, color: string): void {
|
||||
const pts = [project(v, i, j, 0), project(v, i + 1, j, 0), project(v, i + 1, j + 1, 0), project(v, i, j + 1, 0)];
|
||||
const my = pts.reduce((sum, [, y]) => sum + y, 0) / 4;
|
||||
fill(ctx, pts.map(([x, y]) => [x, my + (y - my) * u] as Point), color, 1);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Ely Office opening</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
overflow: hidden;
|
||||
background: #252525;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="frame" width="1920" height="1080"></canvas>
|
||||
<script type="module" src="./page.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,41 @@
|
||||
// Draws one global frame of the opening onto the canvas.
|
||||
import { boxes, cell, ground } from "./draw.ts";
|
||||
import { END, FIRST, HEIGHT, WIDTH, flip, flips, pieces, view } from "./plan.ts";
|
||||
|
||||
const DARK = "#252525";
|
||||
const LIGHT = "#fbfbfa";
|
||||
|
||||
const canvas = document.querySelector<HTMLCanvasElement>("#frame");
|
||||
const ctx = canvas?.getContext("2d");
|
||||
if (!canvas || !ctx) throw new Error("index.html lacks #frame");
|
||||
|
||||
/** Field cells flip light ring by ring until bar 5. */
|
||||
function field(f: number, v: ReturnType<typeof view>) {
|
||||
const done = f >= flips[flips.length - 1];
|
||||
ctx!.fillStyle = done ? LIGHT : DARK;
|
||||
ctx!.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
if (done) return;
|
||||
const corners = [[0, 0], [WIDTH, 0], [0, HEIGHT], [WIDTH, HEIGHT]].map(([x, y]) => ground(v, x, y));
|
||||
const xs = corners.map(([x]) => x);
|
||||
const ys = corners.map(([, y]) => y);
|
||||
for (let i = Math.floor(Math.min(...xs)) - 1; i <= Math.ceil(Math.max(...xs)); i++)
|
||||
for (let j = Math.floor(Math.min(...ys)) - 1; j <= Math.ceil(Math.max(...ys)); j++) {
|
||||
const u = flip(f, i, j);
|
||||
if (u > 0) cell(ctx!, v, i, j, u, LIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
/** Renders global frame `f`. */
|
||||
function render(f: number): void {
|
||||
if (f < FIRST || f >= END) throw new Error(`frame ${f} is outside the opening`);
|
||||
const v = view(f);
|
||||
field(f, v);
|
||||
boxes(ctx!, v, pieces(f, v));
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
opening: { first: number; end: number; render: typeof render };
|
||||
}
|
||||
}
|
||||
window.opening = { first: FIRST, end: END, render };
|
||||
@@ -0,0 +1,265 @@
|
||||
// What the opening shows at each global frame.
|
||||
import { ACCENT, model } from "../../src/model.ts";
|
||||
import { bezier } from "../scenes/time.ts";
|
||||
import { type Box, type Shown, type View, ground, project } from "./draw.ts";
|
||||
|
||||
export const FPS = 30;
|
||||
export const WIDTH = 1920;
|
||||
export const HEIGHT = 1080;
|
||||
const BEAT = 60 / 112;
|
||||
const LAND = 0.2 * FPS;
|
||||
|
||||
/** Bars 3 to 8: beats 8 to 32. */
|
||||
export const FIRST = frameAt(8);
|
||||
export const END = frameAt(32);
|
||||
|
||||
const settle = bezier(0.2, 0.8, 0.3, 1);
|
||||
const glide = bezier(0.65, 0, 0.35, 1);
|
||||
|
||||
/** The frame nearest a global beat. */
|
||||
export function frameAt(beat: number): number {
|
||||
return Math.round(beat * BEAT * FPS);
|
||||
}
|
||||
|
||||
/** Progress of a move of `span` frames ending on `beat`. */
|
||||
function toward(f: number, beat: number, span = LAND, ease = settle): number {
|
||||
const end = frameAt(beat);
|
||||
return ease(Math.min(1, Math.max(0, (f - (end - span)) / span)));
|
||||
}
|
||||
|
||||
const desk = model[0].blocks[0];
|
||||
const TOP = desk.h;
|
||||
const CX = desk.w / 2;
|
||||
const CY = desk.d / 2;
|
||||
const SEED: [number, number] = [8, 5];
|
||||
|
||||
/** Chebyshev ring of a cell around the seed. */
|
||||
const ring = (i: number, j: number) => Math.max(Math.abs(i - SEED[0]), Math.abs(j - SEED[1]));
|
||||
|
||||
/** Tiles landing per sixteenth, from beat 8; the rest land on 16. */
|
||||
const RAIN: Record<number, number> = {
|
||||
2: 1, 4: 1, 6: 2, 8: 2, 10: 2, 12: 3, 13: 1, 14: 3, 15: 2, 16: 3, 17: 3, 18: 4, 19: 4,
|
||||
20: 5, 21: 5, 22: 6, 23: 6, 24: 7, 25: 8, 26: 9, 27: 10, 28: 11, 29: 12, 30: 13, 31: 14,
|
||||
};
|
||||
|
||||
interface Tile {
|
||||
box: Box;
|
||||
lands: number;
|
||||
falls: number;
|
||||
}
|
||||
|
||||
const tiles: Tile[] = (() => {
|
||||
const cells = Array.from({ length: desk.w * desk.d }, (_, n) => [n % desk.w, Math.floor(n / desk.w)]);
|
||||
const angle = ([i, j]: number[]) => Math.atan2(j - SEED[1], i - SEED[0]);
|
||||
cells.sort((a, b) => ring(a[0], a[1]) - ring(b[0], b[1]) || angle(a) - angle(b));
|
||||
const slots = Object.entries(RAIN).flatMap(([k, n]) => Array<number>(n).fill(Number(k)));
|
||||
return cells.map(([i, j], n) => ({
|
||||
box: { x: i, y: j, z: 0, w: 1, d: 1, h: TOP, tone: desk.tone },
|
||||
lands: frameAt(8 + (slots[n] ?? 32) / 4),
|
||||
falls: Math.round(20 - (11 * n) / cells.length),
|
||||
}));
|
||||
})();
|
||||
|
||||
/** Rise order follows the roads: Doc, Mark, Tree, Table, Show, PDF. */
|
||||
const RISE: [string, number][] = [
|
||||
["ElyDoc", 16.25], ["ElyMark", 17.5], ["ElyTree", 18.5], ["ElyTable", 19.5], ["ElyShow", 20.75], ["ElyPDF", 22],
|
||||
];
|
||||
const parts = RISE.map(([name, beat]) => {
|
||||
const part = model.find((p) => p.name === name);
|
||||
if (!part) throw new Error(`no part ${name}`);
|
||||
return part.blocks.map((box, i) => ({ box, beat: beat + i / 4 }));
|
||||
}).flat();
|
||||
|
||||
const roads = model.find((p) => p.name === "Roads")?.blocks;
|
||||
if (!roads) throw new Error("model has no roads");
|
||||
|
||||
/** A road cut into cells, laid from one end on sixteenths. */
|
||||
function lay(road: Box, n: number, beat: number, reverse = false): { box: Box; beat: number }[] {
|
||||
const long = road.w >= road.d;
|
||||
return Array.from({ length: n }, (_, i) => {
|
||||
const k = reverse ? n - 1 - i : i;
|
||||
const box = long
|
||||
? { ...road, x: road.x + (k * road.w) / n, w: road.w / n }
|
||||
: { ...road, y: road.y + (k * road.d) / n, d: road.d / n };
|
||||
return { box, beat: beat + i / 4 };
|
||||
});
|
||||
}
|
||||
|
||||
const main = lay(roads[3], 18, 19);
|
||||
const paving = [
|
||||
...lay(roads[0], 1, 16.75),
|
||||
{ ...main[0], beat: 17 },
|
||||
...lay(roads[4], 3, 17.25),
|
||||
...lay(roads[5], 4, 18),
|
||||
...main.slice(1).map((c, i) => ({ ...c, beat: 19 + i / 4 })),
|
||||
...lay(roads[1], 1, 20.75),
|
||||
...lay(roads[2], 3, 22.5, true),
|
||||
];
|
||||
|
||||
/** Files hop one cell a beat toward their app. */
|
||||
const STEP = 0.6;
|
||||
const FILE = 0.36;
|
||||
const streams: { path: [number, number][]; spawns: number[] }[] = [
|
||||
{ path: [[4.3, 7.9], [6.2, 7.9]], spawns: [20, 23, 26, 29] },
|
||||
{ path: [[2.3, 4.3], [2.3, 4.9], [12.7, 4.9]], spawns: [22, 25, 28] },
|
||||
{ path: [[6.3, 4.2], [6.3, 4.9], [12.7, 4.9]], spawns: [24, 27, 30] },
|
||||
{ path: [[11, 3.15], [11, 4.9], [12.7, 4.9]], spawns: [25, 28, 31] },
|
||||
];
|
||||
|
||||
function along(path: [number, number][], s: number): [number, number] {
|
||||
for (let i = 1; i < path.length; i++) {
|
||||
const [[ax, ay], [bx, by]] = [path[i - 1], path[i]];
|
||||
const len = Math.hypot(bx - ax, by - ay);
|
||||
if (s <= len || i === path.length - 1) {
|
||||
const u = Math.min(s / len, 1);
|
||||
return [ax + (bx - ax) * u, ay + (by - ay) * u];
|
||||
}
|
||||
s -= len;
|
||||
}
|
||||
throw new Error("a path needs two points");
|
||||
}
|
||||
|
||||
const length = (path: [number, number][]) =>
|
||||
path.slice(1).reduce((sum, [x, y], i) => sum + Math.hypot(x - path[i][0], y - path[i][1]), 0);
|
||||
|
||||
function files(f: number): Shown[] {
|
||||
const out: Shown[] = [];
|
||||
for (const { path, spawns } of streams) {
|
||||
const total = length(path);
|
||||
const hops = Math.ceil(total / STEP);
|
||||
for (const spawn of spawns) {
|
||||
if (f <= frameAt(spawn) - LAND) continue;
|
||||
let [s, lift] = [0, 0];
|
||||
for (let k = 1; k <= hops; k++) {
|
||||
const u = toward(f, spawn + k);
|
||||
s += STEP * u;
|
||||
if (u > 0 && u < 1) lift = 0.35 * Math.sin(Math.PI * toward(f, spawn + k, LAND, (x) => x));
|
||||
}
|
||||
const sink = 1 - toward(f, spawn + hops + 1);
|
||||
if (sink <= 0) continue;
|
||||
const [x, y] = along(path, Math.min(s, total));
|
||||
const drop = 1 - toward(f, spawn);
|
||||
const box = { x: x - FILE / 2, y: y - FILE / 2, z: TOP + 0.08 + lift + drop, w: FILE, d: FILE, h: FILE * sink, tone: ACCENT };
|
||||
out.push({ box, alpha: 1 - drop });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** World turn: a quarter on bar 6, back on bar 7. */
|
||||
function turn(f: number): number {
|
||||
const out = toward(f, 22, 2 * BEAT * FPS, glide);
|
||||
const back = toward(f, 28, 4 * BEAT * FPS, glide);
|
||||
return (Math.PI / 2) * (out - back);
|
||||
}
|
||||
|
||||
const all = model.flatMap((p) => p.blocks);
|
||||
const built = all.filter((b) => b !== desk);
|
||||
const flat = (t: number): View => ({ turn: t, cx: CX, cy: CY, s: 1, ox: 0, oy: 0 });
|
||||
const TURNS = Array.from({ length: 19 }, (_, i) => (i * Math.PI) / 36);
|
||||
|
||||
function extent(list: Box[], turns: number[]): [number, number, number, number] {
|
||||
let [x0, x1, y0, y1] = [Infinity, -Infinity, Infinity, -Infinity];
|
||||
for (const t of turns)
|
||||
for (const b of list)
|
||||
for (const [i, j, k] of [0, 1].flatMap((i) => [0, 1].flatMap((j) => [0, 1].map((k) => [i, j, k])))) {
|
||||
const [x, y] = project(flat(t), b.x + i * b.w, b.y + j * b.d, b.z + k * b.h);
|
||||
[x0, x1, y0, y1] = [Math.min(x0, x), Math.max(x1, x), Math.min(y0, y), Math.max(y1, y)];
|
||||
}
|
||||
return [x0, x1, y0, y1];
|
||||
}
|
||||
|
||||
interface Frame {
|
||||
s: number;
|
||||
ox: number;
|
||||
oy: number;
|
||||
}
|
||||
|
||||
/** Bars 5 and 6: the desk fills 70% of the width. */
|
||||
const wide: Frame = (() => {
|
||||
const [x0, x1] = extent(all, [0]);
|
||||
const [u0, u1, v0, v1] = extent(all, TURNS);
|
||||
const s = Math.min((0.7 * WIDTH) / (x1 - x0), (0.92 * HEIGHT) / (v1 - v0));
|
||||
return { s, ox: WIDTH / 2 - (s * (u0 + u1)) / 2, oy: HEIGHT / 2 - (s * (v0 + v1)) / 2 };
|
||||
})();
|
||||
|
||||
/** Bars 7 and 8: buildings above the lower 35%. */
|
||||
const titled: Frame = (() => {
|
||||
const [, , top] = extent(all, TURNS);
|
||||
const [u0, u1, , bottom] = extent(built, TURNS);
|
||||
const [high, low] = [70, 0.63 * HEIGHT];
|
||||
const s = Math.min(wide.s, (low - high) / (bottom - top));
|
||||
return { s, ox: WIDTH / 2 - (s * (u0 + u1)) / 2, oy: low - s * bottom };
|
||||
})();
|
||||
|
||||
/** Bar 3 opens close on the seed, low in frame. */
|
||||
const close: Frame = (() => {
|
||||
const s = wide.s * 2.6;
|
||||
const [x, y] = project(flat(0), SEED[0] + 0.5, SEED[1] + 0.5, TOP);
|
||||
return { s, ox: WIDTH / 2 - s * x, oy: 0.66 * HEIGHT - s * y };
|
||||
})();
|
||||
|
||||
function blend(a: Frame, b: Frame, u: number): Frame {
|
||||
const s = a.s * (b.s / a.s) ** u;
|
||||
const at = (o: number, fs: number) => (WIDTH / 2 - o) / fs;
|
||||
const py = (o: number, fs: number) => (HEIGHT / 2 - o) / fs;
|
||||
const [wx, wy] = [at(a.ox, a.s) + (at(b.ox, b.s) - at(a.ox, a.s)) * u, py(a.oy, a.s) + (py(b.oy, b.s) - py(a.oy, a.s)) * u];
|
||||
return { s, ox: WIDTH / 2 - s * wx, oy: HEIGHT / 2 - s * wy };
|
||||
}
|
||||
|
||||
/** The camera and turn for frame `f`. */
|
||||
export function view(f: number): View {
|
||||
const pull = toward(f, 16, 8 * BEAT * FPS, glide);
|
||||
const rest = toward(f, 24, 2 * BEAT * FPS, glide);
|
||||
const cam = blend(blend(close, wide, pull), titled, rest);
|
||||
return { turn: turn(f), cx: CX, cy: CY, ...cam };
|
||||
}
|
||||
|
||||
/** Frame when field ring `r` finishes flipping light. */
|
||||
export const flips: number[] = (() => {
|
||||
const fronts = Array.from({ length: 33 }, (_, k) => {
|
||||
const v = view(frameAt(8 + k / 4));
|
||||
const corners = [[0, 0], [WIDTH, 0], [0, HEIGHT], [WIDTH, HEIGHT]].map(([x, y]) => ground(v, x, y));
|
||||
const reach = Math.max(...corners.map(([i, j]) => ring(Math.floor(i), Math.floor(j)))) + 1;
|
||||
return k < 4 ? -1 : k === 32 ? Infinity : reach * ((k - 3) / 29) ** 2.4;
|
||||
});
|
||||
const out: number[] = [];
|
||||
for (let r = 0; out.length === r; r++) {
|
||||
const k = fronts.findIndex((front) => front >= r);
|
||||
out.push(frameAt(8 + k / 4));
|
||||
if (k === 32) break;
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
|
||||
/** Progress of field cell (i, j) toward light. */
|
||||
export function flip(f: number, i: number, j: number): number {
|
||||
const r = ring(i, j);
|
||||
const end = flips[Math.min(r, flips.length - 1)];
|
||||
return settle(Math.min(1, Math.max(0, (f - (end - LAND)) / LAND)));
|
||||
}
|
||||
|
||||
/** Every box on the desk at frame `f`. */
|
||||
export function pieces(f: number, v: View): Shown[] {
|
||||
const out: Shown[] = [];
|
||||
if (f >= frameAt(16)) out.push({ box: desk, alpha: 1 });
|
||||
else
|
||||
for (const t of tiles) {
|
||||
if (f <= t.lands - t.falls) continue;
|
||||
const u = Math.min(1, (f - (t.lands - t.falls)) / t.falls);
|
||||
const [, y] = project(v, t.box.x + 0.5, t.box.y + 0.5, TOP);
|
||||
const off = ((y + 80) * (1 - u * u)) / v.s;
|
||||
out.push({ box: { ...t.box, z: off }, alpha: 1, seam: true });
|
||||
}
|
||||
for (const { box, beat } of parts) {
|
||||
const u = toward(f, beat);
|
||||
if (u <= 0) continue;
|
||||
if (box.z <= TOP + 1e-6) out.push({ box: { ...box, h: box.h * u }, alpha: 1 });
|
||||
else out.push({ box: { ...box, z: box.z + 1 - u }, alpha: u });
|
||||
}
|
||||
for (const { box, beat } of paving) {
|
||||
const u = toward(f, beat);
|
||||
if (u > 0) out.push({ box: { ...box, z: box.z + 0.6 * (1 - u) }, alpha: u });
|
||||
}
|
||||
return [...out, ...files(f)];
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Renders the opening's global frames to PNG, manifest and preview.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { chromium } from "../scenes/node_modules/playwright/index.mjs";
|
||||
import { createServer } from "vite";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const site = resolve(here, "../..");
|
||||
const extra = resolve(here, "../out/extra");
|
||||
const dir = join(extra, "opening");
|
||||
const PAGES = 6;
|
||||
|
||||
const server = await createServer({ root: site, configFile: false, logLevel: "error", server: { port: 0 } });
|
||||
await server.listen();
|
||||
const url = `${server.resolvedUrls.local[0]}video/opening/index.html`;
|
||||
const browser = await chromium.launch();
|
||||
|
||||
/** A film-sized page; any page error stops the run. */
|
||||
async function open() {
|
||||
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1 });
|
||||
page.on("pageerror", (e) => {
|
||||
throw e;
|
||||
});
|
||||
await page.goto(url, { waitUntil: "networkidle" });
|
||||
return page;
|
||||
}
|
||||
|
||||
const pages = await Promise.all(Array.from({ length: PAGES }, open));
|
||||
const { first, end } = await pages[0].evaluate(() => ({ first: window.opening.first, end: window.opening.end }));
|
||||
const only = process.argv.slice(2).map(Number);
|
||||
const frames = only.length ? only : Array.from({ length: end - first }, (_, i) => first + i);
|
||||
if (!only.length) rmSync(dir, { recursive: true, force: true });
|
||||
mkdirSync(dir, { recursive: true });
|
||||
|
||||
const queue = [...frames];
|
||||
await Promise.all(
|
||||
pages.map(async (page) => {
|
||||
for (let f = queue.shift(); f !== undefined; f = queue.shift()) {
|
||||
await page.evaluate((f) => window.opening.render(f), f);
|
||||
await page.screenshot({ path: join(dir, `${String(f).padStart(5, "0")}.png`) });
|
||||
}
|
||||
}),
|
||||
);
|
||||
await browser.close();
|
||||
await server.close();
|
||||
|
||||
if (!only.length) {
|
||||
const manifest = { name: "opening", first, count: end - first, fps: 30, kind: "base" };
|
||||
writeFileSync(join(dir, "manifest.json"), JSON.stringify(manifest, null, 1));
|
||||
const args = ["-y", "-v", "error", "-framerate", "30", "-start_number", String(first), "-i", join(dir, "%05d.png")];
|
||||
args.push("-c:v", "libx264", "-preset", "slow", "-crf", "16", "-pix_fmt", "yuv420p", "-movflags", "+faststart");
|
||||
const run = spawnSync("ffmpeg", [...args, join(extra, "opening.mp4")], { stdio: "inherit" });
|
||||
if (run.status !== 0) throw new Error("ffmpeg failed");
|
||||
console.log(`opening: frames ${first}..${end - 1} (${end - first})`);
|
||||
}
|
||||
Reference in new issue
Block a user