From feae2da9bdc11437415b684d9d872b7b262c1a6f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 15 Jul 2023 20:14:59 +0200 Subject: Tools. --- tools/color.js | 55 ++++++++++++ tools/genlayout.js | 59 +++++++++++++ tools/gentextures.sh | 3 + tools/layout.svg | 208 ++++++++++++++++++++++++++++++++++++++++++++++ tools/maketoken.js | 50 +++++++++++ tools/rock_overlay@2x.png | Bin 0 -> 160515 bytes 6 files changed, 375 insertions(+) create mode 100644 tools/color.js create mode 100644 tools/genlayout.js create mode 100644 tools/gentextures.sh create mode 100644 tools/layout.svg create mode 100644 tools/maketoken.js create mode 100644 tools/rock_overlay@2x.png diff --git a/tools/color.js b/tools/color.js new file mode 100644 index 0000000..d645df7 --- /dev/null +++ b/tools/color.js @@ -0,0 +1,55 @@ +function rgb_to_hsl(rgb, add=0, scale=1) { + if (typeof rgb === "string") { + if (rgb[0] === "#") + rgb = rgb.substring(1) + rgb = parseInt(rgb, 16) + } + + let r = ((rgb >> 16) & 255) / 255 + let g = ((rgb >> 8) & 255) / 255 + let b = ((rgb) & 255) / 255 + let cmin = Math.min(r, g, b) + let cmax = Math.max(r, g, b) + let delta = cmax - cmin + let h = 0, s = 0, l = 0 + + if (delta == 0) + h = 0 + else if (cmax == r) + h = ((g - b) / delta) % 6 + else if (cmax == g) + h = (b - r) / delta + 2 + else + h = (r - g) / delta + 4 + + h = Math.round(h * 60) + + if (h < 0) + h += 360 + + l = (cmax + cmin) / 2 + + s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)) + + l = Math.max(0, Math.min(1, l * scale + add)) + + s = Math.round(s * 100) + l = Math.round(l * 100) + + return "hsl(" + h + "," + s + "%," + l + "%)" +} + +function foo(sel, rgb) { + let bg = rgb_to_hsl(rgb, 0.00, 1.00) + let hi = rgb_to_hsl(rgb, 0.10, 1.00) + let sh = rgb_to_hsl(rgb, -0.10, 1.00) + let bd = rgb_to_hsl(rgb, 0.00, 0.33) + console.log(sel + ` { background-color: ${bg}; border-color: ${hi} ${sh} ${sh} ${hi}; box-shadow: 0 0 0 1px ${bd}, 0px 1px 4px #0008; }`) +} + +foo(".tile.red", "ef0d0e") +foo(".tile.white", "efefef") +foo(".tile.blue", "1895d7") +foo(".tile.gold", "ebce42") +foo(".tile.green", "426545") + diff --git a/tools/genlayout.js b/tools/genlayout.js new file mode 100644 index 0000000..2191d90 --- /dev/null +++ b/tools/genlayout.js @@ -0,0 +1,59 @@ +const fs = require("fs") + +const { round, floor, ceil } = Math + +let boxes = {} +let mode, name, x, y, w, h, cx, cy, rx, ry +let scale = 0.75 + +function flush() { + if (mode === 'rect') { + boxes[name] = [ x * scale |0, y * scale |0, w * scale |0, h * scale |0 ] + } + if (mode === 'circle') { + x = cx - rx + y = cy - ry + w = rx * 2 + h = ry * 2 + boxes[name] = [ x * scale |0, y * scale |0, w * scale |0, h * scale |0 ] + } + x = y = w = h = cx = cy = rx = ry = 0 + name = null +} + +for (let line of fs.readFileSync("tools/layout.svg", "utf-8").split("\n")) { + line = line.trim() + if (line.startsWith(" background.png +zopflipng -y background.png background.png diff --git a/tools/layout.svg b/tools/layout.svg new file mode 100644 index 0000000..a1fb011 --- /dev/null +++ b/tools/layout.svg @@ -0,0 +1,208 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/maketoken.js b/tools/maketoken.js new file mode 100644 index 0000000..525e68f --- /dev/null +++ b/tools/maketoken.js @@ -0,0 +1,50 @@ +const fs = require("node:fs") + +function print_cylinder(output, w, h, tall, color) { + let xoff = 1.5 + let yoff = 1.5 + + let total_w = w + xoff * 2 + let total_h = h + tall + yoff * 2 + + let cx = xoff + w / 2 + let cy = yoff + h / 2 + + let rx = w / 2 + let ry = h / 2 + + let svg = [] + svg.push(``) + + svg.push(``) + svg.push(``) + svg.push(``) + svg.push(``) + svg.push(``) + svg.push(``) + svg.push(``) + + let path = [] + path.push("M", xoff, cy) + path.push("v", tall) + path.push("a", rx, ry, 0, 0, 0, w, 0) + path.push("v", -tall) + + svg.push(``) + svg.push(``) + + svg.push('') + + fs.writeFileSync(output, svg.join("\n") + "\n") +} + +let WHITE = [ 'hsl(0,0%,30%)', 'hsl(0,0%,90%)', 'hsl(0,0%,70%)', 'hsl(0,0%,80%)', 'hsl(0,0%,83%)' ] +let RED = [ 'hsl(359,85%,20%)', 'hsl(359,85%,50%)', 'hsl(359,85%,35%)', 'hsl(359,85%,45%)', 'hsl(359,85%,48%)' ] +let BLUE = [ 'hsl(220,85%,25%)', 'hsl(220,85%,55%)', 'hsl(220,85%,40%)', 'hsl(220,85%,50%)', 'hsl(220,85%,53%)' ] + +// let W = 50, H = 33, T = 22 +let W = 38, H = 25, T = 16 + +print_cylinder("images/token_white.svg", W, H, T, WHITE) +print_cylinder("images/token_red.svg", W, H, T, RED) +print_cylinder("images/token_blue.svg", W, H, T, BLUE) diff --git a/tools/rock_overlay@2x.png b/tools/rock_overlay@2x.png new file mode 100644 index 0000000..8710ab6 Binary files /dev/null and b/tools/rock_overlay@2x.png differ -- cgit v1.2.3