-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
61 lines (49 loc) · 1.86 KB
/
ui.js
File metadata and controls
61 lines (49 loc) · 1.86 KB
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
"use strict"
var body = document.getElementsByTagName("body")[0]
startup ()
magmaGenerator () // since there is no point to the main menu yet..
function startup ()
{ body.removeChild (document.getElementById("js-notice")) }
function magmaGenerator ()
{
document.getElementById ("main-menu").style.display = "none"
document.getElementById ("magma-generator").style.display = "block"
var input = document.getElementById ("generator-input")
input.addEventListener ("keyup", function(event)
{ if (event.keyCode == 13) generate() })
}
function generate ()
{
var query = document.getElementById ("generator-input").value
var width = Number (document.getElementById ("generator-width").value)
showAll(query.split(","), width, document.getElementById ("generator-results"))
}
function showAll (properties = [], elements = 3, element = document.getElementsByTagName("body")[0])
{
var magmas = Magma.filteredBinaryOps (properties, elements)
var container = document.createElement("section")
container.className = "listing"
var header = document.createElement("h2")
header.innerHTML = "<strong>" + properties.join () + "</strong> with " + elements + " elements (" + magmas.length + ")"
header.onclick = function ()
{
if (container.classList.contains ("collapsed"))
container.classList.remove ("collapsed")
else container.classList.add ("collapsed")
}
header.ondblclick = function ()
{
container.remove()
}
container.appendChild(header)
element.appendChild(container)
for (var magma of magmas)
container.appendChild(magma.opToHTMLTable())
}
function psychedelic (element = document.body)
{
const phi = (1 + Math.sqrt(5)) / 2
const num2color = (num) => "hsl(" + (- num * phi * 360) + ", 100%, " + (50 + Math.sin(num * 2) * 25) + "%)"
for (var cell of Array.from(element.getElementsByTagName("td")))
cell.style["background-color"] = num2color (Number (cell.innerText))
}