-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
173 lines (157 loc) · 6.36 KB
/
main.js
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
/* The Expectorant website
This uses expectorant.js for the business logic and spinner.js for visually
spinning the spinner.
*/
const INITPROB = .5 // the probability the spinner is preloaded with
// Faire made a poll for voting on these: https://forms.gle/QrRRuRm2PqH3U4KY6
// Now we shuffle them and stick "easter egg salad" on the end.
const VITTLES = [...shuffle([
"five-spice fudge fajitas", // bluastelo
"celery sundae", // bluastelo & danny
"nightshade nutmeg nachos", // bluastelo
"marshmallow mustard muffins", // bluastelo
"chili cheese cotton candy", // GPT
"apple vanilla nachos", // bluastelo
"chelation cheeze", // bluastelo
"garlic fudge nachos", // bluastelo & danny
"kraken quesadillas", // GPT
"wasabi waffles", // GPT
"banana n' mustard sliders", // GPT
"apple n' liver pâté panini", // GPT
"blueberry n' beef jerky parfait", // GPT
"tofu teriyaki tater tots", // GPT
"crusty creamy croissant crumpet crumble", // bluastelo
"cabbage kabobs", // danny
"ketchup n' mustard spaghetti ice cream", // cantor
"deep fried mustard seed n' cricket soup", // faire
"lady n' tramp spaghetti", // danny & cantor
"peanut butter n' jelly jalapeño jambalaya", // christopher/GPT
"bubble gum n' butter sauce buffalo wings", // christopher/GPT
"pineapple pickle pizza", // christopher/GPT
"deep-fried gazpacho", // danny
"pickled mayonnaise lemonade", // melanie & eric
"cucumber n' chocolate chip cookies", // christopher/GPT
"glazed eel partially dipped in white chocolate with ketchup", // ryan
"flaming hot cheetos n' marshmallow fluff milkshake", // christopher/GPT
"apple skin n' sugared watermelon tacos", // ryan
"avocado n' gummy bear salad", // christopher/GPT
"lime peel n' watermelon seed stir fry", // christopher/GPT
"deep-fried green tea n' coca-cola gummies", // ryan
"deep-fried beet-flavored twinkies", // ryan
"jellyfish jelly doughnuts", // GPT
"pickle n' potato chip milkshake", // GPT
"honey mustard ice cream sundae", // GPT
"chocolate-covered chicken nuggets", // GPT
"bacon-wrapped pickle n' cream cheese bites", // GPT
"sardine n' marshmallow kabobs", // GPT
"peanut butter n' jelly milkshake", // GPT
"cold beet with mustard ice cream soup", // dreiley, real thing
"pulled pork n' mashed potato parfait", // the internet
"avocado milkshake", // the internet
"lobster ice cream", // the internet
"mac n' cheetos", // real thing
"marmite milkshake", // danny
"cotton candy kimchi cupcakes", // GPT-4.5
"sriracha strawberry shortcake sliders", // GPT-4.5
]), "easter egg salad"]
let vindex = 0 // which vittle to use as an example in the instructions
const CLOG = console.log
const ASSERT = console.assert
function $(id) { return document.getElementById(id) } // to be jQuery-esque
let spincount = 0 // We show this under the input field
let lastp = null // Just some global variables to track the fraction of yeses
let yeses = 0 // for all the spins we've done since we last changed the
let trials = 0 // probability.
// Take a probability and a spin object, pick the winner and spin that puppy
function expectorize(spob) {
$('theanswer').innerHTML = ' '
$('counter').innerHTML = ++spincount
$('vittle').innerHTML = VITTLES[++vindex % VITTLES.length]
$('audiotag1').play()
spindraw(spob)
const p = spob.slots[0].prob // probability for first slot ie YES
//CLOG("WARNING: Flipped the probs from [p,1-p] to [1-p,p] for testing!")
const windex = spinpick([0, 1], [p, 1-p]) // land on slot 0 with probability p
if (p === lastp) {
yeses += windex === 0 ? 1 : 0
trials += 1
} else {
lastp = p
yeses = windex === 0 ? 1 : 0
trials = 1
}
CLOG(`🥁 Gonna land on slot ${windex} ie ${['YES','NO'][windex]} ` +
`bringing us to ` +
`${yeses}/${trials} = ${percentify(yeses/trials)} yeses so far w/ p=${p}`)
spingo(spob, windex)
}
function expectorizeRepay(spob) {
expectorize(spob)
}
document.addEventListener('DOMContentLoaded', () => { // -------- document-ready
$('expr').focus() // this can be annoying when developing cuz it steals focus
$('prob').innerHTML = INITPROB
$('vittle').innerHTML = VITTLES[vindex]
const spob = spinit(document.querySelector('#spinneroo'), genslots(INITPROB))
spindraw(spob)
function redrawSlots() {
const p = probabilify($('expr').value)
$('prob').innerHTML = roundp(p, 8) // max 17; make it big for debugging
spob.slots = genslots(p)
spindraw(spob)
}
// Update the slots and redraw the spinner on every keystroke in the input field
$('expr').addEventListener('input', e => { redrawSlots() })
$('expectorize').addEventListener('click', e => expectorize(spob))
$('spinneroo') .addEventListener('click', e => expectorize(spob))
$('expr').addEventListener('keyup', e => {
if (e.key==="Enter") expectorize(spob)
})
$('expr').addEventListener('keydown', e => {
if (e.metaKey && e.key === "Enter") expectorize(spob)
})
const fieldNames = ['expr-repay-note1', 'expr-repay-note2', 'expr-repay-owe']
fieldNames.forEach((fieldName) => {
// Make any input update the main input field and redraw the spinner
$(fieldName).addEventListener('input', e => {
const notes = []
if ($('expr-repay-note1').value) {
notes.push($('expr-repay-note1').value)
}
if ($('expr-repay-note2').value) {
notes.push($('expr-repay-note2').value)
}
if (notes.length == 2) {
if (parseInt(notes[0]) > parseInt(notes[1])) {
var swap = notes[0]
notes[0] = notes[1]
notes[1] = swap
}
// 8.27@5,20 means I owe 8.27 but have a $5 note and a $20 note
$('expr').value = `${$('expr-repay-owe').value}@${notes[0]},${notes[1]}`
redrawSlots()
} else {
// 7/20 means I owe 7 but have a $20 note (same as 7@0,20)
$('expr').value = `${$('expr-repay-owe').value}/${notes[0]}`
redrawSlots()
}
})
$(fieldName).addEventListener('keyup', e => {
if (e.key==="Enter") expectorizeRepay(spob)
})
$(fieldName).addEventListener('keydown', e => {
if (e.metaKey && e.key === "Enter") expectorizeRepay(spob)
})
})
$('audiotag1').muted = $('mute').checked
$('mute').addEventListener('change', e => {
$('audiotag1').muted = e.target.checked
})
}) // ------------------------------------------------------- end document-ready
function shuffle(l) {
for (let i = l.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i+1));
[l[i], l[j]] = [l[j], l[i]]
}
return l
}