summaryrefslogtreecommitdiff
path: root/amaryllis.cgi
blob: 83b6e4f9c8f68e4ad7ec14baf40692646aa2c0aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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 })))