-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.html
144 lines (127 loc) · 4.49 KB
/
index.html
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
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Generate random colors">
<meta name="keywords" content="HTML, CSS, JavaScript, Colors">
<meta name="author" content="Jee Vang, Ph.D.">
<meta name="organization" content="One-Off Coder">
<title>Colors</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
* {
font-family: monospace;
}
body {
}
.center {
text-align: center;
}
.color-table {
margin: auto;
width: calc(100vw - 17px);
}
.color-cell {
width: calc((100vw / 25) - 9px);
height: calc((100vw / 25) - 9px);
border-radius: 9%;
padding: 3px;
margin-left: auto;
margin-right: auto;
margin-bottom: 4px;
transform: scale(1, 1);
transition-duration: .3s;
}
.color-cell:hover {
transform: scale(1.15, 1.15);
}
</style>
</head>
<body onload="init()">
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Colors!</h1>
<p class="lead">
Color generator
</p>
<hr class="my-4">
<p>
Hit scramble to generate new colors
</p>
<p>
<a href="https://github.com/oneoffcoder/lightning-projects/tree/master/html/colors" target="_blank">
Source Code
</a>
</p>
<button type="button" class="btn btn-primary" onclick="scramble()">Scramble!</button>
</div>
</div>
<table id="grid" class="color-table">
</table>
<audio id="finished">
<source src="audio/fairy.mp3" type="audio/mp3">
</audio>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.2.0/howler.min.js" crossorigin="anonymous"></script>
<script>
const nRows = 25;
const nCols = 25;
const cells = [];
let isPlayingSound = false;
function init() {
const table = document.getElementById('grid');
for (let r = 0; r < nRows; r++) {
const tr = table.insertRow(r);
for (let c = 0; c < nCols; c++) {
const td = tr.insertCell(c);
const node = document.createElement('div');
node.id = `${r}-${c}`;
node.classList.add('color-cell');
node.style.background = getRandomColor();
td.appendChild(node);
cells.push(node);
}
}
const sound = document.getElementById('finished');
sound.addEventListener('ended', () => {
sound.currentTime = 0;
isPlayingSound = false;
});
updateColors();
}
function updateColors() {
cells.forEach((e, i) => {
e.style.background = getRandomColor();
});
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function playSound() {
const sound = document.getElementById('finished');
sound.play();
}
function scramble() {
if (isPlayingSound) {
return;
}
isPlayingSound = true;
playSound();
updateColors();
}
</script>
</body>
</html>