create it!

This commit is contained in:
conzer 2024-12-06 19:56:54 -05:00
parent 2aa9d9d322
commit 64f4c4a897
4 changed files with 162 additions and 0 deletions

24
src/index.html Normal file
View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mystery Spinner</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container text-center mt-5">
<h1>The Mystery Spinner!</h1>
<p>Try to spin a "1" - but beware, ye evil pirate matey is out to get ya!</p>
<p>I've painted ye spinner here with white paint. Ye won't know what ye will get!</p>
<div class="spinner-container">
<div id="spinner" class="spinner"></div>
<div class="pointer"></div>
</div>
<button id="spinButton" class="btn btn-primary">Spin!</button>
<div id="result" class="mt-3"></div>
</div>
<script src="script.js"></script>
</body>
</html>

57
src/script.js Normal file
View file

@ -0,0 +1,57 @@
const spinner = document.getElementById("spinner");
const resultdiv = document.getElementById("result");
const spinButton = document.getElementById("spinButton");
const emojis = ["🤑", "🥶", "🤢", "😈"];
const evilMessages = ["Oop, try again matey!", "Ho ho ho!"];
function generateSegments() {
spinner.innerHTML = "";
const numSegments = Math.floor(Math.random() * 5) + 6;
for (let i = 0; i < numSegments; i++) {
const segment = document.createElement("div");
segment.className = "spinner-segment";
const randomValue = Math.random();
segment.textContent =
randomValue < 0.2
? emojis[Math.floor(Math.random() * emojis.length)]
: randomValue < 0.25
? "1"
: Math.floor(Math.random() * 10) + 2;
segment.style.transform = `rotate(${(360 / numSegments) * i}deg)`;
segment.style.transform += ` translateY(-50%)`
//segment.innerHTML = `<span>${value}</span>`;
spinner.appendChild(segment)
}
}
function spinWheel() {
const spinDegrees = Math.floor(Math.random() * 5000) + 2000;
const selectedSegmentIndex = Math.floor(Math.random() * spinner.children.length);
const selectedSegment = spinner.children[selectedSegmentIndex];
spinner.style.transition = "transform 4s cubic-bezier(0.25, 0.1, 0.25, 1)";
spinner.style.transform = `rotate(${spinDegrees}deg)`;
setTimeout(() => {
const value = selectedSegment.textContent;
if (value === "1") {
resultdiv.innerHTML = `<h3 class="text-success">You Win!</h3>`;
} else if (emojis.includes(value)) {
resultdiv.innerHTML = `<h3 class="text-warning">You got "${value}"! (Still not 1 though >:) )</h3>`
} else {
resultdiv.innerHTML = `<h3 class="text-danger">${evilMessages[Math.floor(Math.random() * evilMessages.length)]}</h3>`
}
spinButton.disabled = false;
}, 4000);
}
spinButton.addEventListener("click", () => {
resultdiv.innerHTML = "";
spinButton.disabled = true;
generateSegments();
spinWheel();
});
// init
generateSegments();

81
src/styles.css Normal file
View file

@ -0,0 +1,81 @@
body {
font-family: Arial, Helvetica, sans-serif;
background-image: url(wood.avif);
}
h1 {
padding: 10px;
color: black;
background-color: whitesmoke;
border-radius: 10px;
}
p {
padding: 5px;
color: black;
background-color: whitesmoke;
border-radius: 10px;
}
#result {
padding: 10px;
color: black;
background-color: whitesmoke;
border-radius: 10px;
}
.spinner-container {
position: relative;
width: 300px;
height: 300px;
margin: 0 auto;
}
.spinner {
width: 300px;
height: 300px;
border-radius: 50%;
border: 10px solid #ccc;
position: relative;
overflow: hidden;
transform: rotate(-90deg);
}
.spinner-segment {
position: absolute;
width: 100%;
height: 100%;
clip-path: polygon(50% 50%, 100% 0%, 100% 100%);
transform-origin: 50% 50%;
background-color: white;
display: flex;
border: 1px solid #ddd;
text-align: center;
line-height: 150px;
font-size: 14px;
transition: transform 4s ease;
color: black;
}
.spinner-segment span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-50deg);
text-align: center;
font-weight: bold;
color: black;
}
.pointer {
width: 10px;
height: 60px;
background: red;
position: absolute;
top: 120px;
left: 145px;
z-index: 10;
}
#spinButton {
margin-top: 20px;
}

BIN
src/wood.avif Normal file

Binary file not shown.