Prompt specification
Build or customize the Three.js 3D scene "Schedule a call across regions" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Schedule a call across regions
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schedule-a-call-across-regions-x1352
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing time zones and local solar time. Let users move a shared time slider for three referenced cities. Show local clock readings and daylight estimates separately, using supplied dates and documented time-zone data. Low-poly.
Working Three.js Starter (schedule-a-call-across-regions-x1352):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Three Cities — Civil Time & Local Solar Time</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 22, 38, 0.82);
--panel-strong: rgba(9, 20, 34, 0.94);
--line: rgba(164, 196, 220, 0.16);
--text: #edf6ff;
--muted: #91a8bd;
--accent: #76d6ff;
--london: #62d6a4;
--new-york: #ff8878;
--tokyo: #7da8ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select,
input[type="date"] {
color: var(--text);
background: rgba(255, 255, 255, 0.055);
border: 1px solid var(--line);
border-radius: 9px;
}
button {
cursor: pointer;
padding: 7px 10px;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(164, 196, 220, 0.34);
}
button:active {
transform: translateY(1px);
}
select,
input[type="date"] {
width: 100%;
padding: 9px 10px;
outline: none;
}
select:focus,
input:focus {
border-color: rgba(118, 214, 255, 0.6);
}
#scene-container,
#scene-container canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene-container canvas {
display: block;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.city-label {
position: absolute;
min-width: 132px;
padding: 7px 10px;
border: 1px solid var(--line);
border-left: 3px solid var(--city-color);
border-radius: 9px;
background: rgba(5, 13, 24, 0.86);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(10px);
transform: translate(-50%, -115%);
transition: opacity 120ms ease;
font-size: 11px;
line-height: 1.45;
}
.city-label strong {
display: block;
color: #fff;
font-size: 12px;
}
.city-label span {
color: var(--muted);
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
max-width: 580px;
pointer-events: auto;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.3vw, 31px);
font-weight: 650;
letter-spacing: -0.035em;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.subtitle {
margin-top: 6px;
color: #b6c8d8;
font-size: 12px;
line-height: 1.45;
}
.view-actions {
display: flex;
gap: 7px;
pointer-events: auto;
}
.view-actions button {
background: var(--panel);
backdrop-filter: blur(12px);
}
.panel {
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
}
.left-rail {
position: fixed;
z-index: 9;
left: 20px;
top: 98px;
width: 326px;
padding: 16px;
}
.right-panel {
position: fixed;
z-index: 9;
top: 98px;
right: 20px;
bottom: 20px;
width: 392px;
padding: 16px;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(118, 214, 255, 0.35) transparent;
}
.panel-title {
margin: 0 0 4px;
font-size: 15px;
font-weight: 700;
}
.panel-copy {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.field-label {
display: block;
margin: 13px 0 6px;
color: #afc3d5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.utc-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-top: 15px;
padding: 11px 12px;
border: 1px solid rgba(118, 214, 255, 0.18);
border-radius: 10px;
background: rgba(118, 214, 255, 0.055);
}
.utc-readout span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.utc-readout strong {
font-variant-numeric: tabular-nums;
font-size: 20px;
letter-spacing: -0.025em;
}
#timeSlider {
width: 100%;
margin: 13px 0 3px;
accent-color: var(--accent);
cursor: pointer;
}
.timeline-labels {
display: flex;
justify-content: space-between;
color: #72899d;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.button-row {
display: flex;
gap: 7px;
margin-top: 12px;
}
.button-row button {
flex: 1;
font-size: 11px;
}
#playButton {
color: #041019;
background: var(--accent);
border-color: transparent;
font-weight: 750;
}
.toggle-row {
display: flex;
flex-wrap: wrap;
gap: 10px 14px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #b8cada;
font-size: 10px;
}
.toggle-row label {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
}
.toggle-row input {
accent-color: var(--accent);
}
.hint {
margin-top: 12px;
color: #7890a5;
font-size: 10px;
line-height: 1.5;
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 20px 0 9px;
}
.section-heading:first-child {
margin-top: 0;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.01em;
}
.section-heading span {
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.clock-card,
.day-card {
margin-bottom: 8px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.026);
}
.city-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.city-name {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.city-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--city-color);
box-shadow: 0 0 12px var(--city-color);
}
.city-name strong {
display: block;
font-size: 12px;
}
.city-name small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.focus-button {
padding: 4px 7px;
color: #a9bed0;
font-size: 9px;
}
.clock-time {
margin-top: 9px;
font-size: 31px;
font-weight: 620;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.clock-date {
margin-top: 5px;
color: #a8bbcd;
font-size: 10px;
}
.clock-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 11px;
}
.clock-grid > div {
padding: 7px 8px;
border-radius: 8px;
background: rgba(0, 0, 0, 0.14);
}
.clock-grid span,
.solar-row span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.clock-grid b {
display: block;
margin-top: 3px;
font-size: 10px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.solar-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid var(--line);
}
.solar-row b {
color: #d9efff;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.day-card {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px 12px;
}
.day-card .city-heading {
grid-column: 1 / -1;
}
.status {
align-self: center;
padding: 4px 7px;
border-radius: 999px;
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.status.day {
color: #ffe29b;
background: rgba(255, 201, 87, 0.12);
}
.status.twilight {
color: #f4bf89;
background: rgba(244, 151, 89, 0.12);
}
.status.night {
color: #9fb4ff;
background: rgba(113, 137, 255, 0.13);
}
.day-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.day-grid > div {
padding: 7px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.14);
}
.day-grid span {
display: block;
color: var(--muted);
font-size: 8px;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.day-grid b {
display: block;
margin-top: 4px;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.day-extra {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
gap: 12px;
color: var(--muted);
font-size: 9px;
}
.day-extra b {
color: #dcebf8;
font-weight: 600;
}
details {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
summary {
cursor: pointer;
color: #c4d7e7;
font-size: 11px;
font-weight: 650;
}
.data-note {
margin: 10px 0;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.table-wrap {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
th,
td {
padding: 7px 5px;
border-bottom: 1px solid var(--line);
text-align: left;
vertical-align: top;
line-height: 1.4;
}
th {
color: #d9e9f6;
font-weight: 650;
}
td {
color: #9db2c4;
}
.method-note {
margin-top: 12px;
padding: 10px;
border-left: 2px solid rgba(118, 214, 255, 0.5);
border-radius: 0 8px 8px 0;
background: rgba(118, 214, 255, 0.04);
color: #8fa8bd;
font-size: 9px;
line-height: 1.55;
}
.method-note a {
color: #a9ddf2;
}
@media (max-width: 920px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.subtitle {
display: none;
}
.left-rail {
left: 12px;
right: 12px;
top: auto;
bottom: 12px;
width: auto;
padding: 12px;
}
.right-panel {
top: 72px;
left: 12px;
right: 12px;
bottom: 238px;
width: auto;
padding: 12px;
}
.timeline-labels,
.hint {
display: none;
}
.field-label {
margin-top: 9px;
}
.utc-readout {
margin-top: 9px;
}
.button-row {
margin-top: 8px;
}
.toggle-row {
margin-top: 9px;
padding-top: 9px;
}
}
@media (max-width: 520px) {
h1 {
font-size: 18px;
}
.view-actions button {
padding: 6px 8px;
font-size: 10px;
}
.right-panel {
bottom: 260px;
}
.clock-time {
font-size: 27px;
}
}
</style>
</head>
<body>
<div id="scene-container" aria-hidden="true"></div>
<div id="labels" aria-hidden="true"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Three references · one instant</div>
<h1>Civil clocks & local solar time</h1>
<div class="subtitle">
London, New York, and Tokyo on a shared UTC timeline.
Civil time and daylight are calculated and displayed independently.
</div>
</div>
<div class="view-actions">
<button id="autoRotateButton" type="button">Auto rotate</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</header>
<aside class="left-rail panel" aria-label="Shared time controls">
<h2 class="panel-title">Shared reference moment</h2>
<p class="panel-copy">
Choose a supplied date, then drag the slider through one UTC day.
Every city remains on the same absolute instant.
</p>
<label class="field-label" for="datePreset">Reference date</label>
<select id="datePreset">
<option value="2025-03-20">20 Mar 2025 — March equinox</option>
<option value="2025-06-21" selected>21 Jun 2025 — June solstice</option>
<option value="2025-09-22">22 Sep 2025 — September equinox</option>
<option value="2025-12-21">21 Dec 2025 — December solstice</option>
<option value="2025-03-09">09 Mar 2025 — U.S. DST starts</option>
<option value="2025-03-30">30 Mar 2025 — Europe DST starts</option>
<option value="2025-10-26">26 Oct 2025 — Europe DST ends</option>
<option value="2025-11-02">02 Nov 2025 — U.S. DST ends</option>
<option value="custom">Custom date</option>
</select>
<label class="field-label" for="dateInput">Calendar date (UTC)</label>
<input id="dateInput" type="date" value="2025-06-21">
<div class="utc-readout">
<span>UTC instant</span>
<strong id="utcReadout">21 Jun · 12:00</strong>
</div>
<input
id="timeSlider"
type="range"
min="0"
max="1439"
step="1"
value="720"
aria-label="UTC time of day"
>
<div class="timeline-labels" aria-hidden="true">
<span>00:00</span>
<span>06:00</span>
<span>12:00</span>
<span>18:00</span>
<span>24:00</span>
</div>
<div class="button-row">
<button id="backButton" type="button">−15 min</button>
<button id="playButton" type="button">▶ Play</button>
<button id="forwardButton" type="button">+15 min</button>
</div>
<div class="toggle-row">
<label>
<input id="zoneToggle" type="checkbox" checked>
Civil-zone guides
</label>
<label>
<input id="solarToggle" type="checkbox" checked>
Solar meridians
</label>
<label>
<input id="terminatorToggle" type="checkbox" checked>
Day/night ring
</label>
</div>
<div class="hint">
Drag to orbit · wheel to zoom · double-click to reset.
Colored bands mark the center of each civil UTC offset, not the full
political boundary of an IANA time zone.
</div>
</aside>
<main class="right-panel panel" aria-label="City clocks and daylight estimates">
<div class="section-heading">
<h2>Local civil clocks</h2>
<span>IANA time zones</span>
</div>
<div id="clockCards"></div>
<div class="section-heading">
<h2>Daylight estimates</h2>
<span>Solar calculation</span>
</div>
<div id="dayCards"></div>
<details>
<summary>Time-zone data and methodology</summary>
<p class="data-note">
Civil clock readings use the IANA identifiers below through the browser's
ECMAScript <code>Intl.DateTimeFormat</code> implementation. The documented
rules describe the ordinary 2025 schedules; the IANA database remains
authoritative for exact historical and future transitions.
</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Reference</th>
<th>IANA zone</th>
<th>Standard</th>
<th>Documented daylight-saving rule</th>
</tr>
</thead>
<tbody id="zoneDataBody"></tbody>
</table>
</div>
<div class="method-note">
<strong>Solar method.</strong>
Sunrise, sunset, day length, solar noon, and solar altitude use
low-precision NOAA-style solar equations with a −0.833° geometric
horizon. Expected error is generally a few minutes, increasing near
polar latitudes and special refraction conditions. “Mean local solar
time” is the longitude-based sundial time, including the equation of
time; it is not the same as a civil UTC offset.<br><br>
Reference data:
<a href="https://www.iana.org/time-zones" target="_blank" rel="noopener">IANA Time Zone Database</a>,
<a href="https://www.nist.gov/pml/time-and-frequency-division/local-time-faqs" target="_blank" rel="noopener">NIST local-time guidance</a>,
and the standard European and United States daylight-saving statutes.
</div>
</details>
</main>
<noscript>This visualization requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Reference data
// -------------------------------------------------------------------------
const cities = [
{
id: "london",
name: "London",
country: "United Kingdom",
lat: 51.5074,
lon: -0.1278,
timeZone: "Europe/London",
standardOffset: 0,
color: 0x62d6a4,
css: "#62d6a4",
rule:
"DST from the last Sunday in March at 01:00 UTC through the last Sunday in October at 01:00 UTC."
},
{
id: "new-york",
name: "New York",
country: "United States",
lat: 40.7128,
lon: -74.0060,
timeZone: "America/New_York",
standardOffset: -300,
color: 0xff8878,
css: "#ff8878",
rule:
"DST from the second Sunday in March at 02:00 local standard time through the first Sunday in November at 02:00 local daylight time."
},
{
id: "tokyo",
name: "Tokyo",
country: "Japan",
lat: 35.6762,
lon: 139.6503,
timeZone: "Asia/Tokyo",
standardOffset: 540,
color: 0x7da8ff,
css: "#7da8ff",
rule: "No daylight-saving time; UTC+09:00 throughout the year."
}
];
const cityById = Object.fromEntries(cities.map(city => [city.id, city]));
// -------------------------------------------------------------------------
// Application state
// -------------------------------------------------------------------------
const state = {
date: "2025-06-21",
minute: 720,
playing: false,
showZones: true,
showSolar: true,
showTerminator: true,
autoRotate: false
};
const DEG = Math.PI / 180;
const RAD = 180 / Math.PI;
const GLOBE_RADIUS = 2;
const sceneContainer = document.getElementById("scene-container");
const labelsContainer = document.getElementById("labels");
const datePreset = document.getElementById("datePreset");
const dateInput = document.getElementById("dateInput");
const timeSlider = document.getElementById("timeSlider");
const utcReadout = document.getElementById("utcReadout");
const playButton = document.getElementById("playButton");
const backButton = document.getElementById("backButton");
const forwardButton = document.getElementById("forwardButton");
const zoneToggle = document.getElementById("zoneToggle");
const solarToggle = document.getElementById("solarToggle");
const terminatorToggle = document.getElementById("terminatorToggle");
const autoRotateButton = document.getElementById("autoRotateButton");
const resetButton = document.getElementById("resetButton");
// -------------------------------------------------------------------------
// Date and civil-time helpers
// -------------------------------------------------------------------------
function getInstant() {
const base = new Date(`${state.date}T00:00:00Z`);
base.setUTCMinutes(base.getUTCMinutes() + state.minute);
return base;
}
function getDateParts(date, timeZone) {
const formatter = new Intl.DateTimeFormat("en-CA", {
timeZone,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hourCycle: "h23"
});
const values = {};
for (const part of formatter.formatToParts(date)) {
if (part.type !== "literal") {
values[part.type] = Number(part.value);
}
}
return values;
}
function getOffsetMinutes(date, timeZone) {
const formatter = new Intl.DateTimeFormat("en-US", {
timeZone,
timeZoneName: "longOffset"
});
for (const part of formatter.formatToParts(date)) {
if (part.type === "timeZoneName") {
const match = part.value
.trim()
.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);
if (match) {
const sign = match[1] === "+" ? 1 : -1;
const hours = Number(match[2]);
const minutes = Number(match[3] || 0);
return sign * (hours * 60 + minutes);
}
if (/^GMT$/.test(part.value.trim())) {
return 0;
}
}
}
// Fallback for runtimes without the longOffset formatter option.
const parts = getDateParts(date, timeZone);
const representedAsUTC = Date.UTC(
parts.year,
parts.month - 1,
parts.day,
parts.hour,
parts.minute,
parts.second
);
return Math.round(
(representedAsUTC - Math.floor(date.getTime() / 1000) * 1000) / 60000
);
}
function formatOffset(offsetMinutes) {
const sign = offsetMinutes < 0 ? "−" : "+";
const absolute = Math.abs(offsetMinutes);
const hours = String(Math.floor(absolute / 60)).padStart(2, "0");
const minutes = String(absolute % 60).padStart(2, "0");
return `UTC${sign}${hours}:${minutes}`;
}
function formatClock(date, timeZone) {
return new Intl.DateTimeFormat("en-GB", {
timeZone,
hour: "2-digit",
minute: "2-digit",
hourCycle: "h23"
}).format(date);
}
function formatLocalDate(date, timeZone) {
return new Intl.DateTimeFormat("en-US", {
timeZone,
weekday: "short",
year: "numeric",
month: "short",
day: "numeric"
}).format(date);
}
function getZoneAbbreviation(date, timeZone) {
const formatter = new Intl.DateTimeFormat("en-US", {
timeZone,
hour: "2-digit",
timeZoneName: "short"
});
for (const part of formatter.formatToParts(date)) {
if (part.type === "timeZoneName") {
return part.value;
}
}
return "—";
}
function formatMinutes(minutes) {
const normalized = ((minutes % 1440) + 1440) % 1440;
const hour = Math.floor(normalized / 60);
const minute = Math.round(normalized % 60);
return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
}
function formatDayLength(minutes) {
const rounded = Math.max(0, Math.round(minutes));
return `${Math.floor(rounded / 60)}h ${String(rounded % 60).padStart(2, "0")}m`;
}
function formatUTC(date) {
const parts = getDateParts(date, "UTC");
const month = new Intl.DateTimeFormat("en-US", {
timeZone: "UTC",
month: "short"
}).format(date);
return `${month} ${parts.day} · ${formatMinutes(
parts.hour * 60 + parts.minute
)}`;
}
// -------------------------------------------------------------------------
// Solar calculations: NOAA-style low-precision equations
// -------------------------------------------------------------------------
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function solarBasics(date) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth();
const day = date.getUTCDate();
const startOfYear = Date.UTC(year, 0, 1);
const dayOfYear =
Math.floor((Date.UTC(year, month, day) - startOfYear) / 86400000) + 1;
const utcHour =
date.getUTCHours() +
date.getUTCMinutes() / 60 +
date.getUTCSeconds() / 3600;
const gamma =
(2 * Math.PI / 365) * (dayOfYear - 1 + (utcHour - 12) / 24);
const equationOfTime =
229.18 *
(0.000075 +
0.001868 * Math.cos(gamma) -
0.032077 * Math.sin(gamma) -
0.014615 * Math.cos(2 * gamma) -
0.040849 * Math.sin(2 * gamma));
const declination =
0.006918 -
0.399912 * Math.cos(gamma) +
0.070257 * Math.sin(gamma) -
0.006758 * Math.cos(2 * gamma) +
0.000907 * Math.sin(2 * gamma) -
0.002697 * Math.cos(3 * gamma) +
0.00148 * Math.sin(3 * gamma);
return {
equationOfTime,
declination,
gamma
};
}
function getSolarState(date, city) {
const basics = solarBasics(date);
const utcMinutes =
date.getUTCHours() * 60 +
date.getUTCMinutes() +
date.getUTCSeconds() / 60;
const trueSolarMinutes =
(utcMinutes + basics.equationOfTime + 4 * city.lon + 1440) % 1440;
const hourAngle = (trueSolarMinutes / 4 - 180) * DEG;
const latitude = city.lat * DEG;
const declination = basics.declination;
const cosineZenith =
Math.sin(latitude) * Math.sin(declination) +
Math.cos(latitude) *
Math.cos(declination) *
Math.cos(hourAngle);
const zenith = Math.acos(clamp(cosineZenith, -1, 1));
const altitude = 90 - zenith * RAD;
let status = "night";
if (altitude > -0.833) status = "day";
else if (altitude > -6) status = "twilight";
return {
altitude,
status,
meanSolarMinutes: trueSolarMinutes
};
}
function getDaylightEstimate(date, city) {
const local = getDateParts(date, city.timeZone);
const localYear = local.year;
const localMonth = local.month;
const localDay = local.day;
const offset = getOffsetMinutes(date, city.timeZone);
const approximateLocalNoonUTC =
Date.UTC(localYear, localMonth - 1, localDay, 12) -
offset * 60000;
const approximation = new Date(approximateLocalNoonUTC);
const utcYear = approximation.getUTCFullYear();
const utcMonth = approximation.getUTCMonth();
const utcDay = approximation.getUTCDate();
const basics = solarBasics(approximation);
const utcMidnight = Date.UTC(utcYear, utcMonth, utcDay);
// Solar noon in UTC minutes after the beginning of the corresponding UTC day.
const solarNoonUTC =
utcMidnight +
(720 - 4 * city.lon - basics.equationOfTime) * 60000;
const latitude = city.lat * DEG;
const declination = basics.declination;
const cosineHourAngle =
(Math.cos(90.833 * DEG) -
Math.sin(latitude) * Math.sin(declination)) /
(Math.cos(latitude) * Math.cos(declination));
let polarDay = false;
let polarNight = false;
let hourAngle = 0;
if (cosineHourAngle > 1) {
polarDay = true;
} else if (cosineHourAngle < -1) {
polarNight = true;
} else {
hourAngle = Math.acos(cosineHourAngle) * RAD;
}
const sunriseUTC = solarNoonUTC - hourAngle * 4 * 60000;
const sunsetUTC = solarNoonUTC + hourAngle * 4 * 60000;
const dayLengthMinutes = hourAngle * 8;
return {
localDate: new Date(
Date.UTC(localYear, localMonth - 1, localDay, 12)
),
sunrise: polarDay || polarNight ? null : new Date(sunriseUTC),
sunset: polarDay || polarNight ? null : new Date(sunsetUTC),
solarNoon: new Date(solarNoonUTC),
dayLengthMinutes: polarDay ? 1440 : polarNight ? 0 : dayLengthMinutes,
polarDay,
polarNight
};
}
// -------------------------------------------------------------------------
// UI cards
// -------------------------------------------------------------------------
const clockCards = {};
const dayCards = {};
document.getElementById("clockCards").innerHTML = cities
.map(
city => `
<article class="clock-card" style="--city-color:${city.css}">
<div class="city-heading">
<div class="city-name">
<span class="city-dot"></span>
<div>
<strong>${city.name}</strong>
<small>${city.country} · ${city.timeZone}</small>
</div>
</div>
<button class="focus-button" type="button" data-focus="${city.id}">
Focus
</button>
</div>
<div class="clock-time" id="clock-${city.id}">--:--</div>
<div class="clock-date" id="date-${city.id}"></div>
<div class="clock-grid">
<div>
<span>Current UTC offset</span>
<b id="offset-${city.id}"></b>
</div>
<div>
<span>Zone abbreviation</span>
<b id="abbr-${city.id}"></b>
</div>
</div>
<div class="solar-row">
<span>Mean local solar time</span>
<b id="solar-time-${city.id}"></b>
</div>
</article>
`
)
.join("");
document.getElementById("dayCards").innerHTML = cities
.map(
city => `
<article class="day-card" style="--city-color:${city.css}">
<div class="city-heading">
<div class="city-name">
<span class="city-dot"></span>
<div>
<strong>${city.name}</strong>
<small id="solar-date-${city.id}"></small>
</div>
</div>
<span class="status" id="status-${city.id}"></span>
</div>
<div class="day-grid">
<div>
<span>Sunrise</span>
<b id="sunrise-${city.id}">—</b>
</div>
<div>
<span>Sunset</span>
<b id="sunset-${city.id}">—</b>
</div>
<div>
<span>Day length</span>
<b id="length-${city.id}">—</b>
</div>
</div>
<div class="day-extra">
<span>Solar noon <b id="noon-${city.id}">—</b></span>
<span>Solar altitude <b id="altitude-${city.id}">—</b></span>
</div>
</article>
`
)
.join("");
for (const city of cities) {
clockCards[city.id] = {
clock: document.getElementById(`clock-${city.id}`),
date: document.getElementById(`date-${city.id}`),
offset: document.getElementById(`offset-${city.id}`),
abbreviation: document.getElementById(`abbr-${city.id}`),
solarTime: document.getElementById(`solar-time-${city.id}`)
};
dayCards[city.id] = {
date: document.getElementById(`solar-date-${city.id}`),
status: document.getElementById(`status-${city.id}`),
sunrise: document.getElementById(`sunrise-${city.id}`),
sunset: document.getElementById(`sunset-${city.id}`),
length: document.getElementById(`length-${city.id}`),
noon: document.getElementById(`noon-${city.id}`),
altitude: document.getElementById(`altitude-${city.id}`)
};
}
document.getElementById("zoneDataBody").innerHTML = cities
.map(
city => `
<tr>
<td><strong>${city.name}</strong></td>
<td><code>${city.timeZone}</code></td>
<td>${formatOffset(city.standardOffset)}</td>
<td>${city.rule}</td>
</tr>
`
)
.join("");
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
80
);
const hemisphereLight = new THREE.HemisphereLight(
0x9fc9e8,
0x08111f,
0.72
);
scene.add(hemisphereLight);
const sunlight = new THREE.DirectionalLight(0xffedc5, 2.3);
sunlight.position.set(5, 2, 4);
scene.add(sunlight);
scene.add(sunlight.target);
const globeGroup = new THREE.Group();
scene.add(globeGroup);
function latLonToVector(latitude, longitude, radius = GLOBE_RADIUS) {
const lat = latitude * DEG;
const lon = longitude * DEG;
const cosLat = Math.cos(lat);
return new THREE.Vector3(
radius * cosLat * Math.sin(lon),
radius * Math.sin(lat),
radius * cosLat * Math.cos(lon)
);
}
const earth = new THREE.Mesh(
new THREE.SphereGeometry(GLOBE_RADIUS, 32, 20),
new THREE.MeshStandardMaterial({
color: 0x123b58,
roughness: 0.96,
metalness: 0.02,
flatShading: true
})
);
globeGroup.add(earth);
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(2.095, 32, 20),
new THREE.MeshBasicMaterial({
color: 0x65caff,
transparent: true,
opacity: 0.055,
side: THREE.BackSide,
depthWrite: false
})
);
globeGroup.add(atmosphere);
// Coarse, deliberately simplified low-poly continents.
const continentPolygons = [
{
color: 0x356f62,
points: [
[-168, 71], [-145, 70], [-126, 59], [-110, 55], [-94, 49],
[-77, 52], [-60, 47], [-65, 34], [-81, 25], [-88, 30],
[-97, 19], [-108, 29], [-117, 33], [-126, 48], [-143, 59]
]
},
{
color: 0x3b765f,
points: [
[-81, 12], [-67, 10], [-52, 3], [-35, -7], [-42, -23],
[-53, -34], [-67, -55], [-75, -43], [-79, -17]
]
},
{
color: 0x477b68,
points: [
[-54, 82], [-22, 76], [-31, 62], [-52, 58], [-64, 66]
]
},
{
color: 0x3e745e,
points: [
[-11, 36], [-9, 49], [4, 58], [24, 61], [36, 51],
[28, 39], [13, 35], [3, 42]
]
},
{
color: 0x4c7b60,
points: [
[-17, 36], [9, 37], [33, 31], [50, 12], [42, -12],
[31, -34], [11, -35], [-2, -12], [-9, 4]
]
},
{
color: 0x477861,
points: [
[28, 70], [60, 73], [100, 76], [145, 69], [178, 64],
[178, 48], [151, 45], [135, 35], [123, 30], [111, 20],
[100, 8], [91, 21], [78, 8], [69, 23], [48, 30], [35, 43]
]
},
{
color: 0x46735b,
points: [
[47, -13], [52, -17], [59, -25], [53, -39],
[44, -38], [37, -30], [39, -18]
]
},
{
color: 0x4a785f,
points: [
[113, -22], [122, -15], [136, -12], [153, -25],
[146, -39], [130, -35], [115, -34]
]
},
{
color: 0x78907e,
points: [
[-180, -70], [-120, -73], [-60, -68], [0, -72],
[60, -68], [120, -72], [180, -70], [180, -90], [-180, -90]
]
}
];
function addPolygon(points, color) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let index = 1; index < points.length; index++) {
shape.lineTo(points[index][0], points[index][1]);
}
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
const positions = geometry.attributes.position;
for (let index = 0; index < positions.count; index++) {
const longitude = positions.getX(index);
const latitude = positions.getY(index);
const point = latLonToVector(latitude, longitude, 2.016);
positions.setXYZ(index, point.x, point.y, point.z);
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color,
roughness: 0.97,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
})
);
globeGroup.add(mesh);
const outlinePoints = points.map(([longitude, latitude]) =>
latLonToVector(latitude, longitude, 2.026)
);
const outlineGeometry = new THREE.BufferGeometry().setFromPoints(
outlinePoints
);
const outline = new THREE.LineLoop(
outlineGeometry,
new THREE.LineBasicMaterial({
color: 0x89ad98,
transparent: true,
opacity: 0.34
})
);
globeGroup.add(outline);
}
for (const polygon of continentPolygons) {
addPolygon(polygon.points, polygon.color);
}
// Geographic grid.
const gridMaterial = new THREE.LineBasicMaterial({
color: 0x9bc3d9,
transparent: true,
opacity: 0.12
});
for (let longitude = -180; longitude < 180; longitude += 30) {
const points = [];
for (let latitude = -90; latitude <= 90; latitude += 3) {
points.push(latLonToVector(latitude, longitude, 2.032));
}
globeGroup.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
)
);
}
for (let latitude = -60; latitude <= 60; latitude += 30) {
const points = [];
for (let longitude = -180; longitude <= 360; longitude += 3) {
points.push(latLonToVector(latitude, longitude, 2.032));
}
globeGroup.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
)
);
}
// Deterministic stars.
let randomSeed = 739391;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const starPositions = [];
for (let index = 0; index < 420; index++) {
const radius = 13 + random() * 18;
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
starPositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
}
const stars = new THREE.Points(
new THREE.BufferGeometry().setFromPoints(
starPositions.map(value => new THREE.Vector3(value[0], value[1], value[2]))
),
new THREE.PointsMaterial({
color: 0xc4d9e9,
size: 0.035,
transparent: true,
opacity: 0.7,
sizeAttenuation: true
})
);
scene.add(stars);
// Sun marker and camera-facing halo.
const sunMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.115, 1),
new THREE.MeshBasicMaterial({ color: 0xffd675 })
);
scene.add(sunMarker);
const sunHalo = new THREE.Mesh(
new THREE.RingGeometry(0.18, 0.225, 40),
new THREE.MeshBasicMaterial({
color: 0xffd675,
transparent: true,
opacity: 0.7,
side: THREE.DoubleSide,
depthWrite: false
})
);
scene.add(sunHalo);
// Day/night terminator great circle.
const terminatorPositions = new Float32Array(160 * 3);
const terminatorGeometry = new THREE.BufferGeometry();
terminatorGeometry.setAttribute(
"position",
new THREE.BufferAttribute(terminatorPositions, 3)
);
const terminatorLine = new THREE.LineLoop(
terminatorGeometry,
new THREE.LineBasicMaterial({
color: 0xffca76,
transparent: true,
opacity: 0.42
})
);
scene.add(terminatorLine);
function updateTerminator(sunDirection) {
const normal = sunDirection.clone().normalize();
const reference =
Math.abs(normal.y) < 0.9
? new THREE.Vector3(0, 1, 0)
: new THREE.Vector3(1, 0, 0);
const basisA = new THREE.Vector3()
.crossVectors(reference, normal)
.normalize();
const basisB = new THREE.Vector3()
.crossVectors(normal, basisA)
.normalize();
const attribute = terminatorGeometry.attributes.position;
for (let index = 0; index < 160; index++) {
const angle = (index / 160) * Math.PI * 2;
const point = basisA
.clone()
.multiplyScalar(Math.cos(angle) * 2.045)
.add(basisB.clone().multiplyScalar(Math.sin(angle) * 2.045));
attribute.setXYZ(index, point.x, point.y, point.z);
}
attribute.needsUpdate = true;
terminatorGeometry.computeBoundingSphere();
}
// Civil UTC-offset guide centered on the corresponding 15-degree meridian.
function createZoneGuide(city) {
const group = new THREE.Group();
const halfWidth = 7.5;
const minimumLatitude = -62;
const maximumLatitude = 79;
const segments = 20;
const vertices = [];
const indices = [];
for (let index = 0; index <= segments; index++) {
const latitude =
minimumLatitude +
((maximumLatitude - minimumLatitude) * index) / segments;
const left = latLonToVector(latitude, -halfWidth, 2.038);
const right = latLonToVector(latitude, halfWidth, 2.038);
vertices.push(left.x, left.y, left.z);
vertices.push(right.x, right.y, right.z);
}
for (let index = 0; index < segments; index++) {
const a = index * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const band = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color: city.color,
transparent: true,
opacity: 0.105,
side: THREE.DoubleSide,
depthWrite: false
})
);
group.add(band);
for (const longitude of [-halfWidth, halfWidth]) {
const points = [];
for (
let latitude = minimumLatitude;
latitude <= maximumLatitude;
latitude += 2
) {
points.push(latLonToVector(latitude, longitude, 2.044));
}
group.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: city.color,
transparent: true,
opacity: 0.34
})
)
);
}
globeGroup.add(group);
return group;
}
// Meridian through the city: the city's local solar-noon guide.
function createSolarMeridian(city) {
const group = new THREE.Group();
const points = [];
for (let latitude = -82; latitude <= 82; latitude += 2) {
points.push(latLonToVector(latitude, 0, 2.047));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: city.color,
transparent: true,
opacity: 0.68,
dashSize: 0.08,
gapSize: 0.055
})
);
line.computeLineDistances();
group.add(line);
globeGroup.add(group);
return group;
}
const cityVisuals = {};
for (const city of cities) {
const marker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.065, 1),
new THREE.MeshBasicMaterial({ color: city.color })
);
marker.position.copy(latLonToVector(city.lat, city.lon, 2.085));
globeGroup.add(marker);
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.095, 0.125, 36),
new THREE.MeshBasicMaterial({
color: city.color,
transparent: true,
opacity: 0.78,
side: THREE.DoubleSide,
depthWrite: false
})
);
halo.position.copy(marker.position);
halo.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
marker.position.clone().normalize()
);
globeGroup.add(halo);
const label = document.createElement("div");
label.className = "city-label";
label.style.setProperty("--city-color", city.css);
label.innerHTML = `
<strong>${city.name}</strong>
<span class="label-time"></span>
`;
labelsContainer.appendChild(label);
cityVisuals[city.id] = {
marker,
halo,
label,
labelTime: label.querySelector(".label-time"),
zoneGuide: createZoneGuide(city),
solarMeridian: createSolarMeridian(city)
};
}
// -------------------------------------------------------------------------
// Direct camera controls: no addon imports
// -------------------------------------------------------------------------
const defaultCamera = {
yaw: 0.56,
pitch: 0.34,
distance: 8.4
};
const cameraGoal = { ...defaultCamera };
const cameraCurrent = { ...defaultCamera };
function setCameraFromState() {
const horizontal = Math.cos(cameraCurrent.pitch) * cameraCurrent.distance;
camera.position.set(
Math.sin(cameraCurrent.yaw) * horizontal,
Math.sin(cameraCurrent.pitch) * cameraCurrent.distance,
Math.cos(cameraCurrent.yaw) * horizontal
);
camera.lookAt(0, 0, 0);
}
function resetCamera() {
Object.assign(cameraGoal, defaultCamera);
state.autoRotate = false;
autoRotateButton.textContent = "Auto rotate";
}
function focusCity(city) {
const point = latLonToVector(city.lat, city.lon, 1);
const length = point.length();
cameraGoal.yaw = Math.atan2(point.x, point.z);
cameraGoal.pitch = Math.asin(point.y / length);
cameraGoal.distance = 6.6;
state.autoRotate = false;
autoRotateButton.textContent = "Auto rotate";
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraGoal.yaw -= deltaX * 0.006;
cameraGoal.pitch = clamp(
cameraGoal.pitch + deltaY * 0.005,
-1.35,
1.35
);
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraGoal.distance = clamp(
cameraGoal.distance * Math.exp(event.deltaY * 0.001),
4.8,
14
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelectorAll("[data-focus]").forEach(button => {
button.addEventListener("click", () => {
focusCity(cityById[button.dataset.focus]);
});
});
resetButton.addEventListener("click", resetCamera);
autoRotateButton.addEventListener("click", () => {
state.autoRotate = !state.autoRotate;
autoRotateButton.textContent = state.autoRotate
? "Stop rotation"
: "Auto rotate";
});
// -------------------------------------------------------------------------
// Timeline controls
// -------------------------------------------------------------------------
let playbackTimer = null;
function setPlaying(playing) {
state.playing = playing;
playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
if (playbackTimer !== null) {
clearInterval(playbackTimer);
playbackTimer = null;
}
if (playing) {
playbackTimer = setInterval(() => {
state.minute = (state.minute + 15) % 1440;
timeSlider.value = String(state.minute);
refresh();
}, 180);
}
}
playButton.addEventListener("click", () => setPlaying(!state.playing));
backButton.addEventListener("click", () => {
state.minute = (state.minute + 1439) % 1440;
timeSlider.value = String(state.minute);
refresh();
});
forwardButton.addEventListener("click", () => {
state.minute = (state.minute + 15) % 1440;
timeSlider.value = String(state.minute);
refresh();
});
timeSlider.addEventListener("input", () => {
state.minute = Number(timeSlider.value);
refresh();
});
datePreset.addEventListener("change", () => {
if (datePreset.value === "custom") {
dateInput.focus();
return;
}
state.date = datePreset.value;
dateInput.value = state.date;
refresh();
});
dateInput.addEventListener("change", () => {
if (!dateInput.value) return;
state.date = dateInput.value;
datePreset.value = "custom";
refresh();
});
zoneToggle.addEventListener("change", () => {
state.showZones = zoneToggle.checked;
});
solarToggle.addEventListener("change", () => {
state.showSolar = solarToggle.checked;
});
terminatorToggle.addEventListener("change", () => {
state.showTerminator = terminatorToggle.checked;
});
// -------------------------------------------------------------------------
// Update calculations, UI, and globe
// -------------------------------------------------------------------------
function refresh() {
const instant = getInstant();
utcReadout.textContent = formatUTC(instant);
for (const city of cities) {
const offset = getOffsetMinutes(instant, city.timeZone);
const abbreviation = getZoneAbbreviation(instant, city.timeZone);
const solar = getSolarState(instant, city);
const daylight = getDaylightEstimate(instant, city);
const clock = clockCards[city.id];
clock.clock.textContent = formatClock(instant, city.timeZone);
clock.date.textContent = formatLocalDate(instant, city.timeZone);
clock.offset.textContent = formatOffset(offset);
clock.abbreviation.textContent = abbreviation;
clock.solarTime.textContent = formatMinutes(solar.meanSolarMinutes);
const day = dayCards[city.id];
day.date.textContent = `Solar date: ${formatLocalDate(
daylight.localDate,
city.timeZone
)}`;
day.status.textContent =
solar.status === "day"
? "Daylight"
: solar.status === "twilight"
? "Twilight"
: "Night";
day.status.className = `status ${solar.status}`;
day.sunrise.textContent = daylight.sunrise
? formatClock(daylight.sunrise, city.timeZone)
: daylight.polarDay
? "Polar day"
: "Polar night";
day.sunset.textContent = daylight.sunset
? formatClock(daylight.sunset, city.timeZone)
: daylight.polarDay
? "Polar day"
: "Polar night";
day.length.textContent = formatDayLength(daylight.dayLengthMinutes);
day.noon.textContent = formatClock(daylight.solarNoon, city.timeZone);
day.altitude.textContent = `${solar.altitude.toFixed(1)}°`;
const visual = cityVisuals[city.id];
// The civil guide rotates to the center longitude of the current
// UTC offset: offsetMinutes / 4 gives degrees.
visual.zoneGuide.rotation.y = (offset / 4) * DEG;
visual.solarMeridian.rotation.y = city.lon * DEG;
visual.zoneGuide.visible = state.showZones;
visual.solarMeridian.visible = state.showSolar;
visual.labelTime.textContent =
`Civil ${formatClock(instant, city.timeZone)} · ` +
`Solar ${formatMinutes(solar.meanSolarMinutes)}`;
}
// Determine the approximate subsolar point for the globe's sun.
const basics = solarBasics(instant);
const utcMinutes =
instant.getUTCHours() * 60 +
instant.getUTCMinutes() +
instant.getUTCSeconds() / 60;
const subsolarLatitude = basics.declination * RAD;
const subsolarLongitude =
(((720 - utcMinutes - basics.equationOfTime) / 4 + 540) % 360) - 180;
const sunDirection = latLonToVector(
subsolarLatitude,
subsolarLongitude,
3.25
);
sunMarker.position.copy(sunDirection);
sunHalo.position.copy(sunDirection);
sunlight.position.copy(sunDirection.clone().multiplyScalar(6));
sunlight.target.position.set(0, 0, 0);
sunlight.target.updateMatrixWorld();
updateTerminator(sunDirection);
terminatorLine.visible = state.showTerminator;
}
// -------------------------------------------------------------------------
// Label projection and render loop
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
function updateCityLabels() {
cameraDirection.copy(camera.position).normalize();
for (const city of cities) {
const visual = cityVisuals[city.id];
const surfaceNormal = visual.marker.position.clone().normalize();
projected.copy(visual.marker.position).project(camera);
const inFront = surfaceNormal.dot(cameraDirection) > 0.035;
const withinView =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
visual.label.style.opacity = inFront && withinView ? "1" : "0";
if (!inFront || !withinView) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
visual.label.style.left = `${x}px`;
visual.label.style.top = `${y}px`;
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (state.autoRotate) {
cameraGoal.yaw += 0.0027;
}
cameraCurrent.yaw +=
(cameraGoal.yaw - cameraCurrent.yaw) * 0.12;
cameraCurrent.pitch +=
(cameraGoal.pitch - cameraCurrent.pitch) * 0.12;
cameraCurrent.distance +=
(cameraGoal.distance - cameraCurrent.distance) * 0.12;
setCameraFromState();
for (let index = 0; index < cities.length; index++) {
const visual = cityVisuals[cities[index].id];
const pulse = 1 + 0.13 * Math.sin(elapsed * 3 + index * 1.8);
visual.halo.scale.setScalar(pulse);
visual.halo.material.opacity = 0.58 + 0.18 * (pulse - 0.87);
}
sunHalo.quaternion.copy(camera.quaternion);
updateCityLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
refresh();
setCameraFromState();
animate();
</script>
</body>
</html>
```