/* LUCE spec renderer: draws the piece exactly as configured (shape, carat to scale, metal, setting, add-ons). */ (function () { var uid = 0; var METAL = { "14k yellow": ["#f3d79a", "#c9a25a", "#8a6a2f"], "18k yellow": ["#f6d58a", "#d1a246", "#8c6420"], "14k white": ["#f4f5f7", "#c4c8ce", "#80858d"], "18k white": ["#f7f8fa", "#cbd0d6", "#868b93"], "14k rose": ["#f3c9b4", "#cf9277", "#8f5a45"], "18k rose": ["#f5c6ad", "#d18d6e", "#8d5440"], "Platinum": ["#eef0f3", "#b9bec6", "#767c85"] }; function mm(ct) { return 6.5 * Math.cbrt(Math.max(ct, 0.01)); } // parametric outline: n points, half-width a function outline(shape, a, n) { var b = a * ({ Oval: 1.4, Pear: 1.5, Marquise: 1.9, Emerald: 1.35, Radiant: 1.2, Cushion: 1.04 }[shape] || 1), pts = [], i, t, x, y, c, s, e; for (i = 0; i < n; i++) { t = (i / n) * Math.PI * 2; c = Math.cos(t); s = Math.sin(t); if (shape === "Pear") { x = s * Math.pow(Math.abs(Math.sin(t / 2)), 1.4) * 1.22; y = -c; } else if (shape === "Marquise") { x = (s < 0 ? -1 : 1) * Math.pow(Math.abs(s), 1.5); y = -c; } else if (shape === "Round" || shape === "Oval" || !shape) { x = s; y = -c; } else { e = { Cushion: 4, Princess: 14, Asscher: 7, Emerald: 9, Radiant: 7 }[shape] || 4; x = (s < 0 ? -1 : 1) * Math.pow(Math.abs(s), 2 / e); y = -(c < 0 ? -1 : 1) * Math.pow(Math.abs(c), 2 / e); } pts.push([x * a, y * b]); } return pts; } function halfH(shape, w) { return w / 2 * ({ Oval: 1.4, Pear: 1.5, Marquise: 1.9, Emerald: 1.35, Radiant: 1.2, Cushion: 1.04 }[shape] || 1); } function poly(p, k) { return p.map(function (q) { return (q[0] * k).toFixed(1) + "," + (q[1] * k).toFixed(1); }).join(" "); } function shapePath(shape, w) { var p = outline(shape, w / 2, 64); return "M" + poly(p, 1).replace(/ /g, " L") + "Z"; } var SH0 = ["#ffffff", "#dfe7ef", "#9aa9b9", "#4c5866", "#c9d4df", "#2f3842", "#eef3f8", "#7d8a98"], SHB = ["#cfe3ff", "#6fa3e8", "#2f63b8", "#14336e", "#5b8fd6", "#0d2552", "#a9ccff", "#24509a"], SH = SH0; function stone(x, y, w, shape, id, rot) { var g = '', N = 16, P = outline(shape, w / 2, N * 2), i, k; var step = shape === "Emerald" || shape === "Asscher"; if (w < 16) { g += ''; g += ''; return g + ""; } if (step) { [1, 0.8, 0.6, 0.42].forEach(function (k2, j) { g += ''; }); [0.125, 0.375, 0.625, 0.875].forEach(function (f) { var q = P[Math.round(f * P.length) % P.length]; g += ''; }); } else { g += ''; for (i = 0; i < N * 2; i++) { var a = P[i], b = P[(i + 1) % (N * 2)], ta = [a[0] * 0.56, a[1] * 0.56], tb = [b[0] * 0.56, b[1] * 0.56]; k = (i * 5 + 3) % SH.length; g += ''; g += ''; } g += ''; for (i = 0; i < N * 2; i += 4) { var q2 = P[i]; g += ''; } } g += ''; var f = w * 0.09; g += ''; return g + ""; } function dots(points, d, id) { var keep = SH; SH = SH0; var o = points.map(function (p) { return stone(p[0], p[1], d, "Round", id); }).join(""); SH = keep; return o; } function arc(cx, cy, rx, ry, a0, a1, n) { var o = []; for (var i = 0; i < n; i++) { var a = a0 + (a1 - a0) * (n === 1 ? 0.5 : i / (n - 1)); o.push([cx + rx * Math.cos(a), cy + ry * Math.sin(a)]); } return o; } function outlinePts(shape, w, off, n) { var hw = w / 2 + off; return outline(shape, hw, n).map(function (p) { return [p[0], p[1] * (halfH(shape, w) + off) / (halfH(shape, w) * (hw / (w / 2)) || 1)]; }); } window.lucePieceSVG = function (spec) { SH = spec.colour === "Blue" ? SHB : SH0; var id = ++uid, piece = spec.piece || "Solitaire", shape = spec.shape || "Round", ct = +spec.ct || 1; var M = METAL[spec.metal] || METAL["14k yellow"], add = spec.addons || [], has = function (k) { return add.indexOf(k) > -1; }; var matte = has("finish"), K = 13; // px per mm var defs = '' + '' + '' + ''; var out = ''; var mg = "url(#m" + id + ")", mb = "url(#mb" + id + ")"; var cx = 200, w = mm(ct) * K; if (/Tennis/.test(piece)) { var chain = piece === "Tennis chain", total = chain ? 140 : 52, per = ct / total, d = Math.max(9, Math.min(30, mm(per) * K * 0.9)); var n = Math.round((chain ? 640 : 520) / (d * 1.12)), pts = []; for (var i = 0; i < n; i++) { var t = i / (n - 1), a = Math.PI * (0.05 + 0.9 * t); pts.push([cx - 150 * Math.cos(a), 120 + (chain ? 300 : 250) * Math.sin(a)]); } out += pts.map(function (p) { return ''; }).join(""); out += dots(pts, d, id); if (!chain) out += ''; } else if (piece === "Studs") { [130, 270].forEach(function (x) { out += ''; if (has("bezel")) out += ''; else [[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function (q) { out += ''; }); out += stone(x, 230, w, shape, id); }); } else { // ring in three-quarter view: back of shank, head, front of shank out += ''; var cigar = piece === "Cigar band", heavy = piece === "Signet" || piece === "Pinky ring", bw = cigar ? 46 : heavy ? 24 : 15, cy = 340, rx = 128, ry = 48; out += ''; var hy = cy - ry - 34; if (cigar) { // wide domed band: no head } else if (piece === "Signet") { var fw = 140, fh = 112; out += ''; out += ''; if (has("coin")) { out += ''; out += '3DOLLARS1854'; } else if (has("handeng")) { for (var e = -3; e <= 3; e++) out += ''; } if (has("rim")) out += dots(outlinePts("Cushion", fw - 20, 0, 22).map(function (p) { return [cx + p[0] * 1.02, hy + p[1] * 0.8]; }), 9, id); if (!has("coin")) { var sw = Math.min(w, 70); out += ''; out += stone(cx, hy, sw, shape, id); } } else { var hh = halfH(shape, w); // gallery under the head out += ''; if (has("halo") && piece !== "Halo") out += dots(arc(cx, hy + hh * 0.55, w * 0.42, 10, 0.15, Math.PI - 0.15, 9), 6, id); if (has("side")) { var sw2 = mm(0.25) * K; out += stone(cx - w / 2 - sw2 / 2 - 4, hy + 6, sw2, shape, id) + stone(cx + w / 2 + sw2 / 2 + 4, hy + 6, sw2, shape, id); } if (piece === "Halo") { var hd = Math.max(7, w * 0.11); out += ''; out += dots(outlinePts(shape, w, hd * 0.75, Math.round((w + hd * 3) * 3.2 / (hd * 1.15))).map(function (p) { return [cx + p[0], hy + p[1]]; }), hd, id); } if (has("bezel") || piece === "Pinky ring" && has("bezel")) out += ''; if (has("ruby")) { var rw = Math.max(26, w * 0.95), rh = rw * 1.45, rxp = cx + w * 0.42 + rw * 0.3; out += ''; out += ''; out += ''; cx -= w * 0.3; } out += stone(cx, hy, w, shape, id); if (!has("bezel")) [[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function (q) { out += ''; }); } if (has("ruby")) cx = 200; // front of shank out += ''; if (cigar && has("flush")) { out += '' + stone(cx, cy + ry, Math.min(w, 40), shape, id); } if (!matte) out += ''; if (piece === "Band") out += dots(arc(cx, cy, rx, ry, Math.PI * 0.08, Math.PI * 0.92, 15), 13, id); if (has("pave") && piece !== "Band") out += dots(arc(cx, cy, rx, ry, Math.PI * 1.08, Math.PI * 1.3, 4).concat(arc(cx, cy, rx, ry, Math.PI * 1.7, Math.PI * 1.92, 4)), 7, id); if (piece === "Halo") out += dots(arc(cx, cy, rx, ry, Math.PI * 1.06, Math.PI * 1.32, 4).concat(arc(cx, cy, rx, ry, Math.PI * 1.68, Math.PI * 1.94, 4)), 7, id); out += ""; } return '' + defs + out + ""; }; /* Photoreal studio render for a spec: piece + shape + metal tone, film variants for coin, ruby and blue. */ window.lucePhotoSrc = function (spec) { var piece = spec.piece || "Solitaire", shape = String(spec.shape || "Round").toLowerCase(), a = spec.addons || [], m = String(spec.metal || "14k yellow").toLowerCase(); var t = m.indexOf("rose") > -1 ? "r" : (m.indexOf("white") > -1 || m.indexOf("platinum") > -1) ? "w" : "y"; var SH = ["round", "oval", "emerald", "cushion", "pear", "princess", "radiant", "marquise", "asscher"]; if (SH.indexOf(shape) < 0) shape = "round"; var b; if (piece === "Signet") b = a.indexOf("coin") > -1 ? "coin" : "signet"; else if (piece === "Cigar band") b = a.indexOf("flush") > -1 ? "cigar-flush" : "cigar"; else if (piece === "Pinky ring") { if (a.indexOf("ruby") > -1) { b = "jersey"; t = "y"; } else if (spec.colour === "Blue") { b = "vegas"; t = "y"; } else b = "pinky-" + shape; } else if (piece === "Halo") b = "halo-" + shape; else if (piece === "Band") b = "band"; else if (piece === "Studs") b = "studs"; else if (piece === "Tennis chain") b = "chain"; else if (piece === "Tennis bracelet") b = "bracelet"; else b = "sol-" + shape; return "ph/" + b + "-" + t + ".jpg"; }; window.lucePhotoHTML = function (spec) { var alt = [spec.piece, spec.shape, spec.metal].filter(Boolean).join(", "); return '' + alt + ' studio render'; }; window.luceRenderAll = function () { document.querySelectorAll("[data-spec]").forEach(function (el) { try { el.innerHTML = window.lucePhotoHTML(JSON.parse(el.getAttribute("data-spec"))); } catch (e) {} }); }; if (document.readyState !== "loading") window.luceRenderAll(); else document.addEventListener("DOMContentLoaded", window.luceRenderAll); })();