import { drawTrunk, fillCircle, fillEllipse, setPixel } from "../common.mjs"; const BARK = Object.freeze([68, 44, 28, 255]); const BARK_SHADOW = Object.freeze([48, 30, 20, 255]); function mysticGlow (foliage) { return [ Math.min(255, foliage[0] + 36), Math.min(255, foliage[1] + 48), Math.min(255, foliage[2] + 28), 255 ]; } function drawLine (image, x0, y0, x1, y1, rgba) { const steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1); for (let i = 0; i <= steps; i++) { const t = i / steps; setPixel(image, Math.round(x0 + (x1 - x0) * t), Math.round(y0 + (y1 - y0) * t), rgba); } } function drawGnarledBranch (image, points, rgba = BARK) { for (let i = 0; i < points.length - 1; i++) { const [x0, y0] = points[i]; const [x1, y1] = points[i + 1]; drawLine(image, x0, y0, x1, y1, rgba); if (i > 0 && i < points.length - 1) { setPixel(image, x0, y0, BARK_SHADOW); } } } function leafCluster (image, x, y, foliage, radius = 2) { fillCircle(image, x, y, radius, foliage); fillCircle(image, x, y, Math.max(1, radius - 1), mysticGlow(foliage)); } /** Elder — gnarled sparse branches, small clusters, mystical ancient silhouette. */ export function drawElderCanopy (image, season, stump, foliage) { drawTrunk(image, 16, 34, 44, 3); drawTrunk(image, 15, 28, 35, 2); setPixel(image, 17, 30, BARK_SHADOW); setPixel(image, 14, 33, BARK_SHADOW); drawGnarledBranch(image, [[16, 30], [14, 26], [11, 21], [9, 16], [7, 11]]); drawGnarledBranch(image, [[16, 29], [18, 24], [21, 19], [23, 14], [25, 9]]); drawGnarledBranch(image, [[15, 32], [10, 28], [7, 23], [5, 18], [4, 13]]); drawGnarledBranch(image, [[17, 31], [22, 27], [26, 22], [28, 17], [29, 12]]); drawGnarledBranch(image, [[16, 28], [16, 22], [15, 16], [16, 10], [16, 6]]); drawGnarledBranch(image, [[11, 21], [13, 19], [15, 17]], BARK_SHADOW); drawGnarledBranch(image, [[21, 19], [19, 17], [17, 15]], BARK_SHADOW); leafCluster(image, 7, 11, foliage, 2); leafCluster(image, 25, 9, foliage, 2); leafCluster(image, 4, 13, foliage, 2); leafCluster(image, 29, 12, foliage, 2); leafCluster(image, 16, 6, foliage, 3); leafCluster(image, 15, 17, foliage, 2); leafCluster(image, 17, 15, foliage, 2); leafCluster(image, 9, 16, foliage, 2); fillEllipse(image, 16, 4, 2, 1, mysticGlow(foliage)); }