-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.js
More file actions
63 lines (53 loc) · 2.34 KB
/
cat.js
File metadata and controls
63 lines (53 loc) · 2.34 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
62
63
const morseCode = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.',
'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---',
'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---',
'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--',
'Z': '--..',
'1': '.----', '2': '..---', '3': '...--', '4': '....-',
'5': '.....', '6': '-....', '7': '--...', '8': '---..',
'9': '----.', '0': '-----',
',': '--..--', '.': '.-.-.-', '?': '..--..', "'": '.----.',
'!': '-.-.--', '/': '-..-.', '(': '-.--.', ')': '-.--.-',
'&': '.-...', ':': '---...', ';': '-.-.-.', '=': '-...-',
'+': '.-.-.', '-': '-....-', '_': '..--.-', '"': '.-..-.',
'$': '...-..-', '@': '.--.-.'
};
function translateToMorse() {
const inputText = document.getElementById("inputText").value.toUpperCase();
let morseOutput = "";
for (let char of inputText) {
if (morseCode[char]) {
morseOutput += morseCode[char] + " ";
} else if (char === " ") {
morseOutput += "/ ";
}
}
document.getElementById("morseOutput").innerText = morseOutput.trim();
}
document.getElementById("translateBtn").addEventListener("click", translateToMorse);
const catContainer = document.getElementById("catContainer");
function createCat() {
const cat = document.createElement("img");
cat.src = "https://media.tenor.com/wbt5jI9nf3IAAAAj/cat-sticker-line-sticker.gif";
cat.className = "cat";
cat.style.left = `${Math.random() * (window.innerWidth - 50)}px`; // Account for cat width
cat.style.top = `${Math.random() * (window.innerHeight - 50)}px`; // Account for cat height
catContainer.appendChild(cat);
moveCat(cat);
}
function moveCat(cat) {
setInterval(() => {
const windowWidth = window.innerWidth - 7000; // Account for cat width
const windowHeight = window.innerHeight - 7000; // Account for cat height
const x = Math.random() * windowWidth;
const y = Math.random() * windowHeight;
cat.style.left = `${x}px`;
cat.style.top = `${y}px`;
}, 2000);
}
// Create multiple cat images
for (let i = 0; i < 5; i++) { // Adjust the number to create more or fewer cats
createCat();
}