Site: isometric geometry, blocks shaded on three faces

This commit is contained in:
ZacharyZhang-NY committed 2026-10-08 22:59:44 -04:00
1 parent 1178aaa4f2
commit 01397eb1e5
14 files changed
+1205 -4

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
/* True isometric: tilt 54.7356°, turn 45°, no perspective. */
:root {
--u: 28px;
--hu: 28px;
}
.stage {
position: relative;
width: calc(var(--w) * var(--u));
height: calc(var(--d) * var(--u));
transform: rotateX(54.7356deg) rotateZ(45deg);
transform-style: preserve-3d;
}
.block {
position: absolute;
left: calc(var(--x) * var(--u));
top: calc(var(--y) * var(--u));
width: calc(var(--w) * var(--u));
height: calc(var(--d) * var(--u));
transform: translateZ(calc(var(--z) * var(--hu)));
transform-style: preserve-3d;
}
.face {
position: absolute;
box-sizing: border-box;
overflow: hidden;
}
/* One colour, three tones; sides overlap seams by 1px. */
.face.top {
inset: 0;
background: var(--tone);
transform: translateZ(calc(var(--h) * var(--hu)));
}
.face.left {
left: 0;
top: calc(var(--d) * var(--u));
width: calc(var(--w) * var(--u) + 1px);
height: calc(var(--h) * var(--hu) + 1px);
background: color-mix(in oklab, var(--tone), black 9%);
transform-origin: top;
transform: rotateX(90deg);
}
.face.right {
left: calc(var(--w) * var(--u));
top: 0;
width: calc(var(--h) * var(--hu) + 1px);
height: calc(var(--d) * var(--u) + 1px);
background: color-mix(in oklab, var(--tone), black 20%);
transform-origin: left;
transform: rotateY(-90deg);
}
+41
View File
@@ -0,0 +1,41 @@
// Isometric blocks: one colour, three shaded faces, no perspective.
/** A block on the grid, in grid units. */
export interface Block {
x: number;
y: number;
z?: number;
w: number;
d: number;
h: number;
tone: string;
}
/** Builds a block: top, left and right faces of one colour. */
export function block(spec: Block, top?: Node): HTMLElement {
const el = document.createElement("div");
el.className = "block";
el.style.setProperty("--x", String(spec.x));
el.style.setProperty("--y", String(spec.y));
el.style.setProperty("--z", String(spec.z ?? 0));
el.style.setProperty("--w", String(spec.w));
el.style.setProperty("--d", String(spec.d));
el.style.setProperty("--h", String(spec.h));
el.style.setProperty("--tone", spec.tone);
for (const face of ["left", "right", "top"]) {
const part = document.createElement("div");
part.className = `face ${face}`;
if (face === "top" && top) part.append(top);
el.append(part);
}
return el;
}
/** The ground: a stage `w` by `d` cells that holds blocks. */
export function stage(w: number, d: number): HTMLElement {
const el = document.createElement("div");
el.className = "stage";
el.style.setProperty("--w", String(w));
el.style.setProperty("--d", String(d));
return el;
}
+11 -1
View File
@@ -1,5 +1,15 @@
import "./style.css";
import "./iso.css";
import { block, stage } from "./iso.ts";
const app = document.querySelector<HTMLElement>("#app");
if (!app) throw new Error("index.html has no #app");
app.textContent = "Ely Office";
const desk = stage(12, 12);
desk.append(
block({ x: 0, y: 0, w: 12, d: 12, h: 0.5, tone: "#e9e9e6" }),
block({ x: 2, y: 2, z: 0.5, w: 3, d: 3, h: 4, tone: "#f4f4f2" }),
block({ x: 7, y: 2, z: 0.5, w: 3, d: 3, h: 2, tone: "#f4f4f2" }),
block({ x: 2, y: 7, z: 0.5, w: 3, d: 3, h: 1, tone: "#3d7fe5" }),
);
app.append(desk);
+6
View File
@@ -8,3 +8,9 @@
body {
margin: 0;
}
#app {
min-height: 100vh;
display: grid;
place-items: center;
}