← Public packages
@kentcdodds/starsnake
Starsnake: steer a snake-like ship Asteroids style, grow a crystal tail, and spend crystals on towers to defend your core. Mobile friendly.
Files
// Renders the app icon set from one generated SVG using headless Chrome.
// Writes .kody/icon.{svg,png}, public/icons/*. Needs playwright-core and CHROME_PATH (default /usr/bin/google-chrome).
import { chromium } from 'playwright-core'
import { mkdirSync, writeFileSync } from 'node:fs'
function art({ pad = 0, round = true }) {
// pad shrinks the artwork toward the center for the maskable icon safe zone.
const cx = 256, cy = 262, R = 150
const n = 27
let beads = ''
const a0 = (-215 * Math.PI) / 180, a1 = (50 * Math.PI) / 180
let hx = 0, hy = 0, ha = 0
for (let i = 0; i < n; i++) {
const t = i / (n - 1)
const a = a0 + (a1 - a0) * t
const x = cx + Math.cos(a) * R, y = cy + Math.sin(a) * R
const r = 12 + t * 10
const hue = 175 - t * 55
const gun = i % 3 === 2 && i > 2
beads += `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${r.toFixed(1)}" fill="${gun ? '#d6ff8a' : `hsl(${hue} 85% ${50 + t * 12}%)`}" stroke="#06241f" stroke-width="4"/>`
if (gun) beads += `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="4" fill="#ff7a3d"/>`
if (i === n - 1) { hx = x; hy = y; ha = a + Math.PI / 2 }
}
const ship = `<g transform="translate(${hx.toFixed(1)} ${hy.toFixed(1)}) rotate(${((ha * 180) / Math.PI).toFixed(1)}) scale(3.6)" filter="url(#g)"><path d="M13 0 L-9 -9 L-4 0 L-9 9 Z" fill="#0d2b2a" stroke="#d9fff4" stroke-width="2.2" stroke-linejoin="round"/><path d="M-8 -3.5 L-18 0 L-8 3.5" fill="#ffb347"/></g>`
const rock = `<g transform="translate(400 120)"><path d="M-38 -10 L-20 -34 L12 -38 L36 -16 L32 18 L6 36 L-24 28 Z" fill="#0f1630" stroke="#aab8d6" stroke-width="6" stroke-linejoin="round" filter="url(#g)"/></g>`
const gem = (x, y, s) => `<g transform="translate(${x} ${y}) scale(${s})" filter="url(#g)"><path d="M0 -14 L10 0 L0 14 L-10 0 Z" fill="#ff7ad9" stroke="#ffd0f4" stroke-width="2.5" stroke-linejoin="round"/></g>`
const core = `<g transform="translate(${cx} ${cy})" filter="url(#g)"><circle r="62" fill="#ff9ad5" opacity=".14"/><path d="M0 -44 L38 0 L0 44 L-38 0 Z" fill="#2a0f2e" stroke="#ff9ad5" stroke-width="7" stroke-linejoin="round"/><circle r="12" fill="#ff9ad5"/></g>`
const towers = `<g filter="url(#g)"><rect x="96" y="372" width="34" height="34" rx="4" fill="#0b1328" stroke="#ffb347" stroke-width="6" transform="rotate(-12 113 389)"/><path d="M413 330 l24 -26 l24 26 l-24 26 z" fill="#0b1328" stroke="#5ef2ff" stroke-width="6" stroke-linejoin="round"/></g>`
const s = 1 - pad
return `<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><defs><filter id="g" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="7" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter><radialGradient id="v" cx="50%" cy="48%" r="75%"><stop offset="0" stop-color="#14224f"/><stop offset="1" stop-color="#060913"/></radialGradient></defs><rect width="512" height="512" ${round ? 'rx="104"' : ''} fill="url(#v)"/><g transform="translate(256 256) scale(${s}) translate(-256 -256)">${rock}${towers}${beads}${core}${gem(150, 108, 1.5)}${gem(440, 430, 1.2)}${ship}</g></svg>`
}
mkdirSync('public/icons', { recursive: true }); mkdirSync('.kody', { recursive: true })
const main = art({}), maskable = art({ pad: 0.2, round: false })
writeFileSync('.kody/icon.svg', main); writeFileSync('public/icons/favicon.svg', main)
const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH || '/usr/bin/google-chrome' })
async function png(svg, size, out, transparent = true) {
const page = await browser.newPage({ viewport: { width: size, height: size } })
await page.setContent(`<style>html,body{margin:0;background:transparent}svg{display:block;width:${size}px;height:${size}px}</style>${svg}`)
await page.screenshot({ path: out, omitBackground: transparent })
await page.close()
}
await png(main, 512, '.kody/icon.png')
await png(main, 512, 'public/icons/icon-512.png')
await png(main, 192, 'public/icons/icon-192.png')
await png(main, 32, 'public/icons/favicon-32.png')
await png(maskable, 512, 'public/icons/icon-maskable-512.png', false)
// iOS draws its own rounded corners: full-bleed square on the dark background.
await png(art({ round: false, pad: 0.06 }), 180, 'public/icons/apple-touch-icon.png', false)
await browser.close()
console.log('icons ok')