From 400f30ef869628123c62cfc12cc30ac6b1c22992 Mon Sep 17 00:00:00 2001 From: sy Date: Wed, 3 Jul 2024 16:01:44 -0400 Subject: init --- static/aseem.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 static/aseem.js (limited to 'static/aseem.js') diff --git a/static/aseem.js b/static/aseem.js new file mode 100644 index 0000000..f8d7b52 --- /dev/null +++ b/static/aseem.js @@ -0,0 +1,62 @@ +'use strict'; + +function randomInteger(min, max) { + /* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random */ + return Math.floor(Math.random() * (max - min)) + min; +} + +function setColor(color) { + document.body.style.backgroundColor = color; +} + +var hexCharacters = '0123456789abcdef'.split(''); +function randomColor() { + var color = '#'; + for (var i = 0; i < 6; i++) { + color += hexCharacters[randomInteger(0, hexCharacters.length)]; + } + return color; +} + +function randomlySetColor() { + setColor(randomColor()); +} + +function move(id, left, top) { + var element = document.getElementById(id); + element.style.left = left + "px"; + element.style.top = top + "px"; +} + +function randomValidPosition(id) { + var width = window.innerWidth; + var height = window.innerHeight; + var element = document.getElementById(id); + return { + left: randomInteger(0, width - element.width), + top: randomInteger(0, height - element.height) + }; +} + +function randomlyMoveElement(id) { + var position = randomValidPosition(id); + move(id, position.left, position.top); +} + +function rotate(text) { + // Adapted from Robert Quitt + return text.substring(1) + text[0]; +} + +var titleText = document.title + ' ' // buffer +setInterval(function() { + randomlySetColor(); + randomlyMoveElement('aseem'); + + // document.title strips out spaces, so helper variable + titleText = rotate(titleText) + document.title = titleText +}, 220); + + +} -- cgit v1.2.3