mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-24 04:02:19 +00:00
The opening's eye opens onto the app, and the globe matches its blue disc
The screen stays shut outside the eye once the logo is centred: a cover the loading screen's colour, with the eye's outline cut out of it, grows with the eye until it reaches past the screen's corners, so the app shows through the eye as it flies at the viewer. The blue disc in the pupil is the drawn planet: it stays with the continents and grid instead of flying out with the eye, and the real globe starts the size of that disc rather than of the smaller ring of continents inside it.
This commit is contained in:
1 parent
b880cf42c0
commit
e39fc96079
3 files changed
+142
-41
No files matched your search
@@ -1,6 +1,6 @@
|
||||
- The app opens with the loading screen's logo turning into the globe: the
|
||||
eye's arcs fly out, the planet in the pupil becomes the real globe, which
|
||||
spins, grows and stops with the whole planet in view over your country, taken
|
||||
from the browser's time zone. The title's logo goes back to that view. A
|
||||
share link, a Stories link, reduced motion and `?intro=0` open as before
|
||||
(gekh, #1909).
|
||||
- The app opens with the loading screen's logo turning into the globe: the eye
|
||||
flies at you and opens onto the app as it grows, and the planet in the pupil
|
||||
becomes the real globe, which spins, grows and stops with the whole planet in
|
||||
view over your country, taken from the browser's time zone. The title's logo
|
||||
goes back to that view. A share link, a Stories link, reduced motion and
|
||||
`?intro=0` open as before (gekh, #1909).
|
||||
+95
-27
@@ -2,22 +2,24 @@ import { cameraOf } from '../render/rendererOf.js';
|
||||
|
||||
/**
|
||||
* The opening: once the world has loaded, the loading screen's logo turns
|
||||
* into the globe. The words fade and the logo glides to the centre; the eye's
|
||||
* arcs fly at the viewer; the drawn planet in the pupil gives way to the real
|
||||
* one, drawn the same size behind it; the real one spins and grows, slowing
|
||||
* until it stops, the whole planet in view, over the start view (the
|
||||
* visitor's country). Everything is timed from one clock, in ms.
|
||||
* into the globe. The words fade and the logo glides to the centre. The
|
||||
* screen is then shut except inside the eye, which flies at the viewer and
|
||||
* opens onto the application as it grows past the screen's edges. The drawn
|
||||
* planet in the pupil (its blue disc) gives way to the real one, drawn the
|
||||
* same size behind it; the real one spins and grows, slowing until it stops,
|
||||
* the whole planet in view, over the start view (the visitor's country).
|
||||
* Everything is timed from one clock, in ms.
|
||||
*/
|
||||
export const OPENING = Object.freeze({
|
||||
/** The words fade and the logo moves to the centre. */
|
||||
centreMs: 450,
|
||||
// The rest is timed from the end of the move.
|
||||
/** The arcs grow and fade. */
|
||||
arcsMs: 700,
|
||||
/** The background clears to the globe. */
|
||||
/** The eye grows past the screen's edges. */
|
||||
eyeMs: 1100,
|
||||
/** Without the logo's own parts (an <img>): the background clears. */
|
||||
veilMs: Object.freeze([200, 700]),
|
||||
/** The drawn planet fades into the real one. */
|
||||
pupilMs: Object.freeze([500, 1100]),
|
||||
pupilMs: Object.freeze([600, 1200]),
|
||||
/** The camera's flight in. */
|
||||
flightStartMs: 300,
|
||||
flightMs: 4200,
|
||||
@@ -26,9 +28,13 @@ export const OPENING = Object.freeze({
|
||||
});
|
||||
|
||||
const EARTH_RADIUS_M = 6371000;
|
||||
// logo.svg: its viewBox width and the drawn planet's radius, in its units.
|
||||
// logo.svg: its viewBox width, the drawn planet's radius (the blue disc) and
|
||||
// the eye's centre, in its units.
|
||||
const LOGO_WIDTH = 775;
|
||||
const PUPIL_RADIUS = 120.33;
|
||||
const PUPIL_RADIUS = 195;
|
||||
const EYE_CENTRE = Object.freeze({ x: 568.8, y: 379 });
|
||||
/** How far past the screen's corners the eye opens. */
|
||||
const EYE_COVER_MARGIN = 1.6;
|
||||
/** Never start further out than this, metres. */
|
||||
const MAX_FAR_HEIGHT_M = 4e8;
|
||||
|
||||
@@ -57,16 +63,22 @@ const span = (t, [from, to]) => clamp01((t - from) / (to - from));
|
||||
export function openingStage(t, timing = OPENING) {
|
||||
const move = clamp01(t / timing.centreMs);
|
||||
const after = t - timing.centreMs;
|
||||
const arcs = easeInCubic(clamp01(after / timing.arcsMs));
|
||||
const eye = clamp01(after / timing.eyeMs);
|
||||
const flight = clamp01((after - timing.flightStartMs) / timing.flightMs);
|
||||
return {
|
||||
/** The words' opacity. */
|
||||
text: 1 - move,
|
||||
/** How far the logo has moved to the centre, 0–1. */
|
||||
centre: easeInOutCubic(move),
|
||||
arcsScale: 1 + 5 * arcs,
|
||||
arcsOpacity: 1 - arcs,
|
||||
/** The loading screen's background opacity. */
|
||||
/** Whether the screen is shut except inside the eye. */
|
||||
shut: move >= 1,
|
||||
/** How far the eye has grown towards covering the screen, 0–1. */
|
||||
eyeGrowth: easeInCubic(eye),
|
||||
/** The eye's own opacity, and that of the shutter around it. */
|
||||
eyeOpacity: 1 - span(eye, [0.6, 1]),
|
||||
shutterOpacity: 1 - span(eye, [0.85, 1]),
|
||||
eyeOpen: eye >= 1,
|
||||
/** The background's opacity where the logo is an <img>. */
|
||||
veil: 1 - span(after, timing.veilMs),
|
||||
pupilOpacity: 1 - span(after, timing.pupilMs),
|
||||
/** The flight's progress, 0–1. */
|
||||
@@ -114,6 +126,44 @@ export function heightForGlobeRadius(radiusPx, { fovy, viewportHeight }) {
|
||||
return EARTH_RADIUS_M / Math.sin(Math.atan(tangent)) - EARTH_RADIUS_M;
|
||||
}
|
||||
|
||||
/**
|
||||
* How much the eye of `eye` size must grow, about its centre at the centre
|
||||
* of `view`, for its opening to reach past the view's corners.
|
||||
*/
|
||||
export function eyeCoverScale(eye, view) {
|
||||
const across = view.width / eye.width;
|
||||
const down = view.height / eye.height;
|
||||
return EYE_COVER_MARGIN * Math.hypot(across, down);
|
||||
}
|
||||
|
||||
/**
|
||||
* The cover around the eye: a shape the loading screen's colour, as large as
|
||||
* any screen, with the eye's outline cut out of it. It sits under the logo's
|
||||
* parts and grows with the eye, so the screen is shut outside the eye and
|
||||
* open inside it.
|
||||
*/
|
||||
function eyeShutter(eye, loadingScreen, win) {
|
||||
const outline = eye.getAttribute('d')?.match(/^[^Zz]*[Zz]/)?.[0];
|
||||
if (!outline) return null;
|
||||
const colour =
|
||||
win.getComputedStyle?.(loadingScreen).backgroundColor || '#000';
|
||||
const far = 1e5;
|
||||
const { x, y } = EYE_CENTRE;
|
||||
const shutter = eye.ownerDocument.createElementNS(
|
||||
'http://www.w3.org/2000/svg',
|
||||
'path',
|
||||
);
|
||||
shutter.setAttribute(
|
||||
'd',
|
||||
`M${x - far},${y - far}H${x + far}V${y + far}H${x - far}Z${outline}`,
|
||||
);
|
||||
shutter.setAttribute('fill', colour);
|
||||
shutter.setAttribute('fill-rule', 'evenodd');
|
||||
shutter.dataset.openingShutter = '';
|
||||
eye.parentNode.insertBefore(shutter, eye.parentNode.firstElementChild);
|
||||
return shutter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the page opens with the opening: not where motion is reduced, not
|
||||
* on a Stories link (Stories opens its own view) and not with `?intro=0`.
|
||||
@@ -162,18 +212,21 @@ export function playOpeningIntro({
|
||||
const logo = loadingScreen.querySelector('.loader-logo');
|
||||
const svg = logo?.querySelector('svg');
|
||||
const part = (id) => svg?.querySelector(`#${id}`);
|
||||
const arcs = [part('outer_eye'), part('inner_eye')].filter(Boolean);
|
||||
// The drawn planet; the whole logo where it is an <img>.
|
||||
const eye = part('outer_eye');
|
||||
// The drawn planet: its blue disc, continents and grid; the whole logo
|
||||
// where it is an <img>.
|
||||
const disc = part('inner_eye');
|
||||
const pupil = svg
|
||||
? [part('globe'), part('globe_cage')].filter(Boolean)
|
||||
? [disc, part('globe'), part('globe_cage')].filter(Boolean)
|
||||
: [logo].filter(Boolean);
|
||||
const shutter = eye ? eyeShutter(eye, loadingScreen, win) : null;
|
||||
|
||||
loadingScreen.classList.add('opening');
|
||||
playing += 1;
|
||||
// The planet looks out of the middle of the eye again.
|
||||
for (const element of pupil) element.style.transform = 'none';
|
||||
const globe = part('globe');
|
||||
const pupilRect = (globe ?? logo)?.getBoundingClientRect();
|
||||
const pupilRect = (disc ?? logo)?.getBoundingClientRect();
|
||||
const eyeRect = eye?.getBoundingClientRect();
|
||||
const view = (
|
||||
doc.getElementById('cesiumContainer') ?? doc.documentElement
|
||||
).getBoundingClientRect();
|
||||
@@ -187,10 +240,10 @@ export function playOpeningIntro({
|
||||
: Math.PI / 3;
|
||||
const lens = { fovy, viewportHeight };
|
||||
const pupilRadius = pupilRect
|
||||
? globe
|
||||
? disc
|
||||
? pupilRect.width / 2
|
||||
: (pupilRect.width * PUPIL_RADIUS) / LOGO_WIDTH
|
||||
: 20;
|
||||
: 32;
|
||||
const farHeight = Math.min(
|
||||
MAX_FAR_HEIGHT_M,
|
||||
Math.max(target.height * 2, heightForGlobeRadius(pupilRadius, lens)),
|
||||
@@ -202,6 +255,12 @@ export function playOpeningIntro({
|
||||
}
|
||||
: { x: 0, y: 0 };
|
||||
const startRadius = globeRadiusPx(farHeight, lens);
|
||||
const eyeCover = eyeRect?.width
|
||||
? eyeCoverScale(
|
||||
{ width: eyeRect.width, height: eyeRect.height },
|
||||
{ width: view.width || win.innerWidth, height: viewportHeight },
|
||||
)
|
||||
: 1;
|
||||
|
||||
let driving = false;
|
||||
const place = (pose, heading = 0, pitch = -Math.PI / 2) => {
|
||||
@@ -263,17 +322,26 @@ export function playOpeningIntro({
|
||||
place(pose);
|
||||
const scale = globeRadiusPx(pose.height, lens) / startRadius;
|
||||
loadingScreen.style.setProperty('--opening-text', stage.text);
|
||||
loadingScreen.style.setProperty('--opening-veil', stage.veil);
|
||||
// Once the logo is centred, the shutter around the eye is the cover.
|
||||
loadingScreen.style.setProperty(
|
||||
'--opening-veil',
|
||||
shutter ? (stage.shut ? 0 : 1) : stage.veil,
|
||||
);
|
||||
if (logo)
|
||||
logo.style.transform = `translate(${toCentre.x * stage.centre}px, ${
|
||||
toCentre.y * stage.centre
|
||||
}px) scale(${scale})`;
|
||||
for (const element of arcs) {
|
||||
element.style.transform = `scale(${stage.arcsScale})`;
|
||||
element.style.opacity = stage.arcsOpacity;
|
||||
const eyeScale = `scale(${1 + (eyeCover - 1) * stage.eyeGrowth})`;
|
||||
if (eye) {
|
||||
eye.style.transform = eyeScale;
|
||||
eye.style.opacity = stage.eyeOpacity;
|
||||
}
|
||||
if (shutter) {
|
||||
shutter.style.transform = eyeScale;
|
||||
shutter.style.opacity = stage.shutterOpacity;
|
||||
}
|
||||
for (const element of pupil) element.style.opacity = stage.pupilOpacity;
|
||||
if (stage.pupilOpacity === 0) hide();
|
||||
if (stage.pupilOpacity === 0 && (stage.eyeOpen || !shutter)) hide();
|
||||
frame = win.requestAnimationFrame(step);
|
||||
};
|
||||
step();
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { Window } from 'happy-dom';
|
||||
import {
|
||||
OPENING,
|
||||
eyeCoverScale,
|
||||
globeRadiusPx,
|
||||
heightForGlobeRadius,
|
||||
openingPlaying,
|
||||
@@ -17,25 +18,47 @@ const TARGET = { lon: 10.4, lat: 51.1, height: 23e6, heading: 0, pitch: -1 };
|
||||
const LANDED = { lon: TARGET.lon, lat: TARGET.lat, height: TARGET.height };
|
||||
const END_MS = OPENING.centreMs + OPENING.flightStartMs + OPENING.flightMs + 1;
|
||||
|
||||
test('the arcs fly out and the words fade before the globe arrives', () => {
|
||||
test('the words fade, then the eye opens past the screen before the globe arrives', () => {
|
||||
const start = openingStage(0);
|
||||
assert.equal(start.text, 1);
|
||||
assert.equal(start.veil, 1);
|
||||
assert.equal(start.shut, false);
|
||||
assert.equal(start.pupilOpacity, 1);
|
||||
assert.equal(start.flight, 0);
|
||||
const centred = openingStage(OPENING.centreMs);
|
||||
assert.equal(centred.text, 0);
|
||||
assert.equal(centred.centre, 1);
|
||||
const arcsGone = openingStage(OPENING.centreMs + OPENING.arcsMs);
|
||||
assert.equal(arcsGone.arcsOpacity, 0);
|
||||
assert.ok(arcsGone.arcsScale > 5);
|
||||
assert.equal(centred.shut, true, 'shut but for the eye');
|
||||
assert.equal(centred.eyeGrowth, 0);
|
||||
const half = openingStage(OPENING.centreMs + OPENING.eyeMs / 2);
|
||||
assert.ok(half.eyeGrowth > 0 && half.eyeGrowth < 0.5, 'it speeds up');
|
||||
assert.equal(half.pupilOpacity, 1, 'the planet stays in the pupil');
|
||||
const open = openingStage(OPENING.centreMs + OPENING.eyeMs);
|
||||
assert.equal(open.eyeGrowth, 1);
|
||||
assert.equal(open.eyeOpen, true);
|
||||
assert.equal(open.eyeOpacity, 0);
|
||||
assert.equal(open.shutterOpacity, 0);
|
||||
const real = openingStage(OPENING.centreMs + OPENING.pupilMs[1]);
|
||||
assert.equal(real.pupilOpacity, 0);
|
||||
assert.equal(real.veil, 0);
|
||||
assert.ok(real.flight > 0 && real.flight < 1);
|
||||
assert.equal(openingStage(END_MS).done, true);
|
||||
});
|
||||
|
||||
test('the open eye reaches past the corners of any screen', () => {
|
||||
const eye = { width: 128, height: 80 };
|
||||
for (const view of [
|
||||
{ width: 1280, height: 720 },
|
||||
{ width: 375, height: 812 },
|
||||
{ width: 3840, height: 1600 },
|
||||
]) {
|
||||
const scale = eyeCoverScale(eye, view);
|
||||
// The eye's opening, taken as the ellipse inside its outline, holds
|
||||
// the corners.
|
||||
const a = (eye.width / 2) * scale;
|
||||
const b = (eye.height / 2) * scale;
|
||||
assert.ok((view.width / 2 / a) ** 2 + (view.height / 2 / b) ** 2 < 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('the flight turns west to east, slows and stops over the target', () => {
|
||||
const far = 4e8;
|
||||
const start = openingPose(0, { target: TARGET, farHeight: far });
|
||||
@@ -92,7 +115,8 @@ function stage() {
|
||||
doc.body.innerHTML = `
|
||||
<div id="cesiumContainer"></div>
|
||||
<div id="loading-screen"><span class="loader-logo"><svg>
|
||||
<path id="outer_eye"/><path id="inner_eye"/>
|
||||
<path id="outer_eye" d="M0,10C0,0,20,0,20,10C20,20,0,20,0,10ZM5,10h1"/>
|
||||
<path id="inner_eye"/>
|
||||
<path id="globe"/><path id="globe_cage"/>
|
||||
</svg></span></div>`;
|
||||
const screen = doc.getElementById('loading-screen');
|
||||
@@ -149,7 +173,16 @@ test('the opening runs to the start view, then hides the cover', async () => {
|
||||
assert.equal(openingPlaying(), true);
|
||||
assert.ok(s.screen.classList.contains('opening'));
|
||||
assert.ok(s.views[0].destination.height > TARGET.height * 2, 'far start');
|
||||
s.advance(OPENING.centreMs + OPENING.pupilMs[1]);
|
||||
const shutter = s.screen.querySelector('[data-opening-shutter]');
|
||||
assert.ok(shutter, 'the cover around the eye');
|
||||
assert.match(
|
||||
shutter.getAttribute('d'),
|
||||
/ZM0,10C0,0,20,0,20,10C20,20,0,20,0,10Z$/,
|
||||
);
|
||||
assert.equal(shutter.getAttribute('fill-rule'), 'evenodd');
|
||||
s.advance(OPENING.centreMs);
|
||||
assert.equal(s.screen.style.getPropertyValue('--opening-veil'), '0');
|
||||
s.advance(Math.max(OPENING.eyeMs, OPENING.pupilMs[1]));
|
||||
assert.ok(s.screen.classList.contains('hidden'));
|
||||
s.advance(OPENING.flightMs);
|
||||
await opening.done;
|
||||
|
||||
Reference in new issue
Block a user