Skip to content

Commit 3aff546

Browse files
committed
global: what have i done
0 parents  commit 3aff546

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# websmash
2+
q: what if we used the web as art?
3+
a: we shouldn't

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta property="og:type" content="website">
7+
<meta property="og:description" content="what if we used the web as art?">
8+
<meta property="og:title" content="websmash">
9+
<title>websmash</title>
10+
</head>
11+
<body>
12+
<script src="index.js"></script>
13+
</body>
14+
</html>

index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This was written with the Nintendo 3DS browser as a target, so forgive the awful code.
2+
3+
// Randomness utils
4+
function getRandomFloat(max, min) {
5+
min = min || 0;
6+
return Math.random() * (max - min) + min;
7+
};
8+
function getRandomInt(max, min) { return Math.floor(getRandomFloat(max, min)) };
9+
function getRandomFromArray(arr) { return arr[getRandomInt(0, arr.length)] };
10+
11+
// Constant values
12+
var ALLOWED_ELEMENTS = ["p", "a", "i", "strong", "button", "textarea", "marquee"]; // TODO: <input /> elements
13+
var INTENSITY = getRandomFloat(4, 2) // TODO: User input for intensity?
14+
15+
// Actual logic
16+
function createElements(words) {
17+
for (let i = 0; i < 50 * INTENSITY; i++) {
18+
var elem = document.createElement(getRandomFromArray(ALLOWED_ELEMENTS));
19+
elem.textContent = getRandomFromArray(words);
20+
elem.href = "javascript:document.location.reload();";
21+
22+
elem.style.position = "fixed";
23+
elem.style.left = getRandomFloat(window.innerWidth) + "px";
24+
elem.style.top = getRandomFloat(window.innerHeight) + "px";
25+
elem.style.height = getRandomFloat(30 * INTENSITY) + "px";
26+
elem.style.transform = "rotate($1deg) scale($2,$3)"
27+
.replace("$1", getRandomFloat(180))
28+
.replace("$2", getRandomFloat(3 * INTENSITY))
29+
.replace("$3", getRandomFloat(3 * INTENSITY));
30+
31+
document.body.appendChild(elem);
32+
}
33+
}
34+
35+
// This fucking sucks
36+
var req = new XMLHttpRequest();
37+
req.overrideMimeType("application/json");
38+
req.open("GET", "https://cdn.jsdelivr.net/npm/an-array-of-english-words", true);
39+
req.onload = function() { createElements(JSON.parse(req.responseText)) };
40+
req.send();

0 commit comments

Comments
 (0)