From d0a64877554ed80a1bcae7fc9d4a3918cb3079ea Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 28 Oct 2026 20:33:13 +0100 Subject: [PATCH] feat: medieval flat palette for the diorama models, forest trees and a well Co-Authored-By: Claude Opus 5.5 --- app/diorama/iso.ts | 9 ++-- app/diorama/models.ts | 118 ++++++++++++++++++++++++++++++------------ 2 files changed, 87 insertions(+), 40 deletions(-) diff --git a/app/diorama/iso.ts b/app/diorama/iso.ts index ff8502d..37193b8 100644 --- a/app/diorama/iso.ts +++ b/app/diorama/iso.ts @@ -12,16 +12,14 @@ export interface Face { color: string /** Planes like fields and banners: shown from either side. */ twoSided?: boolean - /** Skip light shading, e.g. for glowing fire. */ + /** Skip light shading, e.g. for fire. */ flat?: boolean - opacity?: number } export interface Poly { points: string fill: string stroke: string - opacity: number } const VIEW: V3 = [1, 1, 1] @@ -126,7 +124,6 @@ export function toPolys(faces: Face[], offset: V3 = [0, 0, 0]): Poly[] { points: pts.map((p) => project(p).map((v) => v.toFixed(1)).join(',')).join(' '), fill, stroke: scale(fill, 0.86), - opacity: f.opacity ?? 1, }, }) } @@ -258,8 +255,8 @@ export function log(cx: number, cy: number, z: number, len: number, r: number, c } /** A flat, two-sided quad on the ground (fields, pits, paths) or upright (banners). */ -export function plane(pts: V3[], color: string, opacity?: number): Face { - return { pts, color, twoSided: true, opacity } +export function plane(pts: V3[], color: string): Face { + return { pts, color, twoSided: true } } /** Every face moved by (dx, dy, dz). */ diff --git a/app/diorama/models.ts b/app/diorama/models.ts index 7b013eb..cd0bc69 100644 --- a/app/diorama/models.ts +++ b/app/diorama/models.ts @@ -4,38 +4,44 @@ // stone and bigger at high levels. import type { BuildingType } from '~/types/game' -import { box, type Face, hash, house, log, ngon, plane, prism, pyramid, rect, shift, type V2, type V3 } from './iso' +import { box, type Face, hash, house, log, ngon, orient, plane, prism, pyramid, rect, shift, type V2, type V3 } from './iso' +/** Muted medieval colours, all flat: faces get their light from iso.ts shading only. */ export const C = { - wood: '#b98552', - woodDark: '#8d5f36', - plank: '#cfa16a', - thatch: '#d9b65f', - canvas: '#ece2ca', - canvasDark: '#d7c6a2', - roofRed: '#b9573c', - slate: '#6a7482', - stone: '#b9b3a8', - stoneDark: '#948e85', - field: '#a8c65e', - wheat: '#e3c45f', - furrow: '#c9a24e', - soil: '#9c744a', - leaf: '#5f9c46', - leafDark: '#4b8439', - trunk: '#7b5333', - clay: '#cc7a4f', - clayDark: '#a65a37', - clayWet: '#b9683f', - rock: '#8e8983', - ore: '#5e6a78', - fire: '#f4a53b', - banner: '#b9443a', - hay: '#e6cb6c', - cloth: '#7a5f4a', - skin: '#e7bb92', - dark: '#3e342b', - grass: '#86b456', + wood: '#8a5f38', + woodDark: '#6a4526', + plank: '#a67c4e', + thatch: '#b8984f', + canvas: '#d6c7a0', + canvasDark: '#b9a77f', + roofRed: '#94452c', + slate: '#575c63', + stone: '#a39d92', + stoneDark: '#847e74', + field: '#8c9a4c', + wheat: '#c4a552', + furrow: '#9a7c44', + soil: '#7d5c3a', + leaf: '#56703a', + leafDark: '#3f5a2c', + trunk: '#5a3d24', + clay: '#a8643f', + clayDark: '#874c2f', + clayWet: '#96583a', + rock: '#8a857d', + ore: '#4f5a63', + fire: '#d98a2b', + banner: '#7b1e16', + hay: '#c9ad5e', + cloth: '#6b4f3a', + skin: '#d8a982', + dark: '#2f2620', + grass: '#78894a', + conifer: '#3d5a2b', + coniferDark: '#334d25', + broadleaf: '#5a7339', + broadleafDark: '#4c6431', + bush: '#5f7a3c', } export interface Model { @@ -82,12 +88,56 @@ export function tree(x: number, y: number, size: number, seed = 0): Face[] { ] } -export function rock(x: number, y: number, size: number, seed = 0): Face[] { +export function rock(x: number, y: number, size: number, seed = 0, color = C.rock): Face[] { const base = ngon(x, y, size * 0.5, 5, hash(seed, 1) * 6).map(([px, py], i): V2 => { const k = 0.75 + 0.45 * hash(seed, i) return [x + (px - x) * k, y + (py - y) * k] }) - return pyramid(base, 0, size * (0.45 + 0.3 * hash(seed, 9)), C.rock, [x + size * 0.08, y - size * 0.06]) + return pyramid(base, 0, size * (0.45 + 0.3 * hash(seed, 9)), color, [x + size * 0.08, y - size * 0.06]) +} + +// Landscape: lighter trees for the forest around the village (few faces each). + +/** A fir: one tall faceted cone on a short trunk. */ +export function conifer(x: number, y: number, size: number, seed = 0): Face[] { + const rot = hash(seed, 7) * Math.PI + const color = hash(seed, 3) > 0.5 ? C.conifer : C.coniferDark + return [ + ...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.25, C.trunk), + ...pyramid(ngon(x, y, size * 0.36, 5, rot), size * 0.18, size * 1.05, color), + ] +} + +/** A deciduous tree: a faceted crown (two pyramids back to back) on a trunk. */ +export function broadleaf(x: number, y: number, size: number, seed = 0): Face[] { + const rot = hash(seed, 5) * Math.PI + const color = hash(seed, 4) > 0.5 ? C.broadleaf : C.broadleafDark + const ring = ngon(x, y, size * 0.4, 5, rot) + const mid = size * 0.62 + // Downward cone under the crown, flipped so its faces point outwards. + const bottom = pyramid(ring, mid, -size * 0.3, color).map((f) => ({ ...f, pts: orient(f.pts, [x, y, mid]) })) + return [ + ...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.36, C.trunk), + ...bottom, + ...pyramid(ring, mid, size * 0.42, color), + ] +} + +export function bush(x: number, y: number, size: number, seed = 0): Face[] { + return pyramid(ngon(x, y, size * 0.4, 5, hash(seed, 2) * 6), 0, size * 0.35, C.bush) +} + +/** The village well on the plaza. */ +export function well(s: number): Model { + return { + faces: [ + ...prism(ngon(0, 0, s * 0.42, 8), 0, s * 0.32, C.stone, C.dark), + ...post(-s * 0.36, 0, s * 0.85, s * 0.05), + ...post(s * 0.36, 0, s * 0.85, s * 0.05), + ...house(0, 0, s * 0.95, s * 0.55, s * 0.85, s * 0.3, C.woodDark, C.roofRed, 'x').slice(5), + ], + height: s * 1.2, + } } function person(x: number, y: number, s: number, shirt = C.cloth): Face[] { @@ -418,7 +468,7 @@ const models: Record Model> = { } }, - // The wall is drawn as the ring around the plateau, see scene.ts. + // The wall is drawn as the ring around the village, see scene.ts. wall: () => ({ faces: [], height: 0 }), } @@ -431,7 +481,7 @@ export function scaffold(s: number): Model { const a = s * 0.6 return { faces: [ - plane(rect(0, 0, a * 2.1, a * 2.1).map(([x, y]) => [x, y, 0.5]), C.soil, 0.5), + plane(rect(0, 0, a * 2.1, a * 2.1).map(([x, y]) => [x, y, 0.5]), C.soil), ...post(-a, -a, s * 0.75, s * 0.035), ...post(a, -a, s * 0.75, s * 0.035), ...post(-a, a, s * 0.75, s * 0.035),