From fab85f8d639c8b7792775d02a2d3fe22fe96befd Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 19 Dec 2022 02:38:48 -0600 Subject: initial commit --- amaryllis.cgi | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100755 amaryllis.cgi (limited to 'amaryllis.cgi') diff --git a/amaryllis.cgi b/amaryllis.cgi new file mode 100755 index 0000000..83b6e4f --- /dev/null +++ b/amaryllis.cgi @@ -0,0 +1,210 @@ +#!/usr/bin/lua5.1 + +local marigold = require 'marigold' +local lang = require 'language' + +local h = marigold.h +local metavars = marigold.get_metavars() +local settings = marigold.decode_query(metavars.query_string or '') + +settings.seed = tonumber(settings.seed) or os.time() +math.randomseed(settings.seed) + +settings.phonemes = settings.phonemes or [[ +C=mnbdTLshzwrly +V=aeiou +T=1324 +]] + +settings.syllables = settings.syllables or [[ +CVT +CVTl +CVTn +]] + +settings.orthography = settings.orthography or [[ +T=th +L=lh +z=zh +(%V)1=%1́ +(%V)2=%1%1́ +(%V)3=%1 +(%V)4=%1́%1 +]] + +settings.phonemes_decay = settings.phonemes_decay or 'Q' +settings.syllables_decay = settings.syllables_decay or 'Q' + +settings.len_min = settings.len_min or "1" +settings.len_max = settings.len_max or "3" +settings.count = settings.count or "20" + + +local distributions = { + U=lang.uniform, + Q=lang.quadratic, +} + +local p_dist = distributions[settings.phonemes_decay] +local s_dist = distributions[settings.syllables_decay] + + +local l = lang.Language( + settings.phonemes, + settings.syllables, + settings.orthography, + tonumber(settings.len_min), + tonumber(settings.len_max), + p_dist, + s_dist +) + + +local syllable_html = {} +for i=1,tonumber(settings.count) do + table.insert( + syllable_html, + h('li', l:romanize(l:word())) + ) +end +syllable_html = h('ol', syllable_html) + + +function radiobutton(label, name, value, checked) + local radio = h('input', { + type="radio", + name=name, + id = name .. value, + value = value, + checked = (checked and "true") or nil + }) + local lbl = {} + lbl['for'] = name .. value + local label = h('label', label, lbl) + + return h('div', { radio, label }) +end + + +function textarea(name, text, decay) + local children = { class="noborder", + h('legend', name), + h('textarea', text, { name=name, rows="6", spellcheck="false" }), + } + + if decay then table.insert(children, h('fieldset', { + h('legend', name .. ' decay'), + radiobutton("uniform", name .. '_decay', 'U', settings[name .. '_decay'] == 'U'), + radiobutton("quadratic", name .. '_decay', 'Q', settings[name .. '_decay'] == 'Q'), + }) + ) end + + return h('fieldset', children) +end + + +local form = h('form', { + h('label', 'seed', { + h('input', { name="seed", type="number", value=tostring(settings.seed) }), + }), + + h('input', { value="update", type="Submit" } ), + + h('br'), + h('div', { class="form-flex", + textarea('phonemes', settings.phonemes, true), + textarea('syllables', settings.syllables, true), + textarea('orthography', settings.orthography, false), + }), + h('br'), + + h('label', 'min syllables', { + h('input', { name="len_min", type="number", min="1", value=settings.len_min }), + }), + h('br'), + h('label', 'max syllables', { + h('input', { name="len_max", type="number", min="1", value=settings.len_max }), + }), + h('br'), + h('label', '# to generate', { + h('input', { name="count", type="number", min="1", value=settings.count }), + }), + + h('input', { value="update", type="Submit" } ), +}) + + +local body = h('body', { h('div', { id="content", + h('a', '<- projects', { href='https://sanine.net/projects/' }), + h('br'), h('br'), + form, + h('hr'), + syllable_html, + h('a', 'hello there c:', { href="#" }), +})}) + + +local head = h('head', { + h('meta', { charset="utf-8" }), + h('meta', { name="viewport", content="width=device-width, initial-scale=1" }), + h('title', 'amaryllis | sanine.net'), + h('style', [[ + + :root { + --light: #eee; + --dark: #1c1c1c; + --highlight: #f5ae2e; + } + + body { + color: var(--light); + background: var(--dark); + font: 1.3em monospace; + text-size-adjust: auto; + } + + #content { + max-width: 40em; + margin: auto; + } + + .noborder { + border: none; + padding: 0px; + } + + a { + color: var(--highlight); + } + + a:hover { + color: var(--dark); + background: var(--highlight); + text-decoration: none; + } + + .form-flex { + display: flex; + flex-wrap: wrap; + wrap: 100%; + } + + textarea { + color: var(--light); + background: #191919; + border: 1px solid var(--highlight); + } + + input { + font-family: monospace; + color: var(--highlight); + background: var(--dark); + border: 1px solid var(--highlight); + } + ]] + ), +}) + + +print('Content-type: text/html\n') +print(marigold.html(h('html', { head, body }))) -- cgit v1.2.1