feat: map forests as dense clusters of small firs (one symbol per forest field), shallows along the shores, lower and darker mountains
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
45886713c3
commit
3543290042
|
|
@ -20,12 +20,39 @@ interface Field {
|
|||
x: number
|
||||
y: number
|
||||
ground: Ground
|
||||
/** Trees as [x, y, size] in the field's 100 × 100 box, back to front. */
|
||||
trees: [number, number, number][]
|
||||
/** The cluster of firs a forest field wears (a symbol below), by how deep in the forest it lies. */
|
||||
forest: string | null
|
||||
/** A mountain's faces, a little different on every field. */
|
||||
peaks: string[] | null
|
||||
}
|
||||
|
||||
// Forests like the Die Stämme map's: dense clusters of small dark firs. Each forest field
|
||||
// wears one of a few clusters drawn once as a symbol: a few trees at the edge of the forest,
|
||||
// more further in, a thicket deep inside, darker the deeper.
|
||||
interface Fir {
|
||||
x: number
|
||||
y: number
|
||||
size: number
|
||||
}
|
||||
const DENSITY = [3, 6, 10]
|
||||
const FIR_COLOURS = [
|
||||
{ lit: '#3e5034', dark: '#2b3a27' },
|
||||
{ lit: '#384a30', dark: '#273624' },
|
||||
{ lit: '#32432c', dark: '#223020' },
|
||||
]
|
||||
const CLUSTERS = DENSITY.flatMap((n, d) =>
|
||||
[0, 1, 2, 3].map((v) => {
|
||||
const firs: Fir[] = Array.from({ length: n }, (_, i) => ({
|
||||
x: 12 + fieldHash(i * 7 + v * 31, d * 13 + 1) * 76,
|
||||
y: 18 + fieldHash(d * 17 + 3, i * 11 + v * 29) * 70,
|
||||
size: 0.5 + fieldHash(i + v * 5, d + 9) * 0.28,
|
||||
})).sort((a, b) => a.y - b.y)
|
||||
return { id: `map-forest-${d}-${v}`, firs, colours: FIR_COLOURS[d]! }
|
||||
}),
|
||||
)
|
||||
/** Forest floor under the thicker clusters: the grass goes dark there. */
|
||||
const FLOOR = ['#656c46', '#606843']
|
||||
|
||||
const pts = (...p: number[]) => p.reduce((s, v, i) => s + (i % 2 ? `,${v.toFixed(1)}` : `${i ? ' ' : ''}${v.toFixed(1)}`), '')
|
||||
/**
|
||||
* A mountain in the field's 100 × 100 box: a big peak and a smaller one behind it, each a lit
|
||||
|
|
@ -37,8 +64,8 @@ function peaks(x: number, y: number): string[] {
|
|||
const q = fieldHash(y, x)
|
||||
const out: string[] = []
|
||||
for (const [ax, ay, lx, rx, by] of [
|
||||
[24 + q * 14, 18 + r * 10, -2, 60, 84],
|
||||
[48 + r * 12, -14 + q * 14, 14, 100, 94],
|
||||
[24 + q * 14, 30 + r * 10, 0, 58, 82],
|
||||
[50 + r * 12, 8 + q * 12, 16, 98, 92],
|
||||
] as const) {
|
||||
const mx = ax + (rx - ax) * 0.3
|
||||
const my = by + 4
|
||||
|
|
@ -53,7 +80,7 @@ function peaks(x: number, y: number): string[] {
|
|||
return out
|
||||
}
|
||||
/** Fills of a mountain's faces, in the order `peaks` returns them: lit, in shadow, bare rock on each. */
|
||||
const PEAK_FILLS = ['#827d74', '#5a5751', '#9a958b', '#6e6b65']
|
||||
const PEAK_FILLS = ['#78746b', '#55524c', '#8d887f', '#67645e']
|
||||
|
||||
const groundOf = (x: number, y: number): Ground => (props.villages.has(`${x}|${y}`) ? 'grass' : groundAt(x, y))
|
||||
|
||||
|
|
@ -64,6 +91,7 @@ const fields = computed(() => {
|
|||
// The flat ground: one path per grass shade and one for the lakes, a subpath per run of fields.
|
||||
const flat: Record<string, string> = {}
|
||||
let shore = ''
|
||||
let shallows = ''
|
||||
let ripples = ''
|
||||
for (let y = y0; y < y1; y++) {
|
||||
let run: string | null = null
|
||||
|
|
@ -73,7 +101,9 @@ const fields = computed(() => {
|
|||
}
|
||||
for (let x = x0; x <= x1; x++) {
|
||||
const ground = x < x1 ? groundOf(x, y) : null
|
||||
const fill = ground === null ? null : ground === 'water' ? WATER : GRASS[Math.floor(fieldHash(x, y) * GRASS.length)]!
|
||||
const depth = ground === 'forest' ? forestDepth(x, y) : 0
|
||||
const thick = depth > TERRAIN.forest.above ? (depth > 0.7 ? 2 : 1) : 0
|
||||
const fill = ground === null ? null : ground === 'water' ? WATER : thick ? FLOOR[thick - 1]! : GRASS[Math.floor(fieldHash(x, y) * GRASS.length)]!
|
||||
if (fill !== run) {
|
||||
close(x)
|
||||
run = fill
|
||||
|
|
@ -81,54 +111,59 @@ const fields = computed(() => {
|
|||
}
|
||||
if (ground === null || ground === 'grass') continue
|
||||
if (ground === 'water') {
|
||||
// A sandy shore where the lake meets land, and a ripple.
|
||||
// A sandy shore where the lake meets land, then the shallows, a step lighter than the deep water.
|
||||
const land = (gx: number, gy: number) => groundOf(gx, gy) !== 'water'
|
||||
const s = F * 0.09
|
||||
if (land(x, y - 1)) shore += `M${x * F} ${y * F}h${F}v${s}h${-F}z`
|
||||
if (land(x, y + 1)) shore += `M${x * F} ${(y + 1) * F - s}h${F}v${s}h${-F}z`
|
||||
if (land(x - 1, y)) shore += `M${x * F} ${y * F}h${s}v${F}h${-s}z`
|
||||
if (land(x + 1, y)) shore += `M${(x + 1) * F - s} ${y * F}h${s}v${F}h${-s}z`
|
||||
const band = (o: number, s: number) => {
|
||||
let d = ''
|
||||
if (land(x, y - 1)) d += `M${x * F} ${y * F + o}h${F}v${s}h${-F}z`
|
||||
if (land(x, y + 1)) d += `M${x * F} ${(y + 1) * F - o - s}h${F}v${s}h${-F}z`
|
||||
if (land(x - 1, y)) d += `M${x * F + o} ${y * F}h${s}v${F}h${-s}z`
|
||||
if (land(x + 1, y)) d += `M${(x + 1) * F - o - s} ${y * F}h${s}v${F}h${-s}z`
|
||||
return d
|
||||
}
|
||||
shallows += band(F * 0.08, F * 0.1)
|
||||
shore += band(0, F * 0.09)
|
||||
const k = F / 100
|
||||
ripples += `M${(x * 100 + 28 + fieldHash(x, y) * 30) * k} ${(y * 100 + 50) * k}h${18 * k}M${(x * 100 + 40 + fieldHash(y, x) * 20) * k} ${(y * 100 + 64) * k}h${12 * k}`
|
||||
continue
|
||||
}
|
||||
// Deeper in a forest, more and bigger trees.
|
||||
const count = ground === 'forest' ? 2 + Math.round(forestDepth(x, y) * 4) : 0
|
||||
const trees = Array.from({ length: count }, (_, i): [number, number, number] => [
|
||||
14 + fieldHash(x * 3 + i, y) * 72,
|
||||
28 + fieldHash(x, y * 3 + i) * 56,
|
||||
0.75 + fieldHash(x + i, y + i) * 0.5,
|
||||
]).sort((a, b) => a[1] - b[1])
|
||||
out.push({ x, y, ground, trees, peaks: ground === 'mountain' ? peaks(x, y) : null })
|
||||
const forest = ground === 'forest' ? `#map-forest-${thick}-${Math.floor(fieldHash(y, x) * 4)}` : null
|
||||
out.push({ x, y, ground, forest, peaks: ground === 'mountain' ? peaks(x, y) : null })
|
||||
}
|
||||
}
|
||||
return { flat: Object.entries(flat), shore, ripples, raised: out }
|
||||
return { flat: Object.entries(flat), shore, shallows, ripples, raised: out }
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<g>
|
||||
<defs>
|
||||
<symbol v-for="c in CLUSTERS" :id="c.id" :key="c.id" v-once viewBox="0 0 100 100" overflow="visible">
|
||||
<g v-for="(t, i) in c.firs" :key="i" :transform="`translate(${t.x} ${t.y}) scale(${t.size})`">
|
||||
<ellipse cx="5" cy="25" rx="12" ry="4" fill="#4a5233" />
|
||||
<rect x="-2" y="18" width="4" height="8" fill="#3f3328" />
|
||||
<polygon points="0,-12 -12,20 0,16" :fill="c.colours.dark" />
|
||||
<polygon points="0,-12 12,20 0,16" :fill="c.colours.lit" />
|
||||
</g>
|
||||
</symbol>
|
||||
</defs>
|
||||
<path v-for="[fill, d] in fields.flat" :key="fill" :d="d" :fill="fill" />
|
||||
<path v-if="fields.shallows" :d="fields.shallows" fill="#55676a" />
|
||||
<path v-if="fields.shore" :d="fields.shore" :fill="SHORE" />
|
||||
<path v-if="fields.ripples" :d="fields.ripples" stroke="#6a7a80" :stroke-width="field * 0.03" stroke-linecap="round" />
|
||||
<g v-for="f in fields.raised" :key="`${f.x}|${f.y}`" :transform="`translate(${f.x * field} ${f.y * field}) scale(${field / 100})`">
|
||||
<template v-if="f.ground === 'hill'">
|
||||
<ellipse cx="52" cy="70" rx="40" ry="16" fill="#5d6242" />
|
||||
<polygon points="18,72 40,30 58,72" fill="#8a857c" />
|
||||
<polygon points="40,30 58,72 64,60" fill="#5f5c56" />
|
||||
<polygon points="48,74 68,42 86,74" fill="#9a958c" />
|
||||
<polygon points="68,42 86,74 90,66" fill="#6c6962" />
|
||||
<polygon points="22,72 40,40 56,72" fill="#7e7a71" />
|
||||
<polygon points="40,40 56,72 61,63" fill="#5a5751" />
|
||||
<polygon points="50,74 67,50 84,74" fill="#878279" />
|
||||
<polygon points="67,50 84,74 88,67" fill="#64615b" />
|
||||
</template>
|
||||
<template v-else-if="f.peaks">
|
||||
<ellipse cx="50" cy="88" rx="52" ry="14" fill="#5a5e3f" />
|
||||
<polygon v-for="(p, i) in f.peaks" :key="i" :points="p" :fill="PEAK_FILLS[i % 4]" />
|
||||
</template>
|
||||
<g v-for="(tr, i) in f.trees" :key="i" :transform="`translate(${tr[0]} ${tr[1]}) scale(${tr[2]})`">
|
||||
<ellipse cx="4" cy="26" rx="12" ry="4" fill="#4f5535" />
|
||||
<rect x="-2" y="18" width="4" height="9" fill="#4a3b2e" />
|
||||
<polygon points="0,-10 -13,20 0,16" fill="#2b3a27" />
|
||||
<polygon points="0,-10 13,20 0,16" fill="#3e5034" />
|
||||
</g>
|
||||
<use v-if="f.forest" :href="f.forest" width="100" height="100" />
|
||||
</g>
|
||||
</g>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue